Consulting

Results 1 to 4 of 4

Thread: Solved: Turn txtbox on an off

  1. #1
    VBAX Regular
    Joined
    Feb 2009
    Location
    Norfolk ( The English one)
    Posts
    24
    Location

    Solved: Turn txtbox on an off

    Hi can anyone help me please. I have looked everywhere but cannot find a solution to my quandry.

    I have a form that has three text boxes that relate to specific functions. I have 3 other text boxes that will hold hyperlinks to technical manuals. I want to be able to keep the technical references invisible until the user clicks or mouse overs the box.

    I keep reading that there is no way to do an "On_Mouse_Over" or equivilant in excel. Do any of you guys have a workaround?

    On the Form the three main text boxes are

    txtGovCritPass reference textbox = 'txtApppass
    txtGovCritWarn reference textbox = 'txtAppwarn
    txtGovCritFail reference textbox = 'txtAppFail

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    If you have a userform with TextBox1 and TextBox2, this code in the UF code module will hide TextBox2 unless the mouse is over TextBox1.

    (Not critical but the default value of TextBox2's Visible property should be False.)

    [VBA]Private Sub TextBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
    TextBox2.Visible = True
    End Sub

    Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
    TextBox2.Visible = False
    End Sub[/VBA]
    I just realized there is a problem, If the mouse is over TextBox1, TB2 will show. When the user moves the mouse to click on the hyperlink, it will leave TextBox1, hiding TB2. Hm....
    Last edited by mikerickson; 07-28-2009 at 06:19 PM.

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    This seems to work in my testing, in 2007 at least

    This is the code in UserForm1, with 6 textboxes (tbPass, tbPassLink, etc.)


    [vba]
    Option Explicit
    Dim X_Pos As Single, Y_Pos As Single

    Private Sub UserForm_Initialize()
    tbPassLink.Visible = False
    tbWarnLink.Visible = False
    tbFailLink.Visible = False
    End Sub

    Private Sub CommandButton1_Click()
    UserForm1.Hide
    Unload UserForm1
    End Sub
    Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    X_Pos = X
    Y_Pos = Y
    If tbPassLink.Visible Then tbPassLink.Visible = False
    If tbWarnLink.Visible Then tbWarnLink.Visible = False
    If tbFailLink.Visible Then tbFailLink.Visible = False
    End Sub

    Private Sub tbPass_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    X_Pos = tbPass.Left + X
    Y_Pos = tbPass.Top + Y
    If InsideTextbox(tbPass) Then tbPassLink.Visible = True
    End Sub
    Private Sub tbWarn_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    X_Pos = tbWarn.Left + X
    Y_Pos = tbWarn.Top + Y
    If InsideTextbox(tbWarn) Then tbWarnLink.Visible = True
    End Sub
    Private Sub tbFail_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    X_Pos = tbFail.Left + X
    Y_Pos = tbFail.Top + Y
    If InsideTextbox(tbFail) Then tbFailLink.Visible = True
    End Sub
    Function InsideTextbox(tb As msforms.TextBox) As Boolean
    InsideTextbox = False

    If X_Pos < tb.Left Then Exit Function
    If X_Pos > tb.Left + tb.Width Then Exit Function

    If Y_Pos < tb.Top Then Exit Function
    If Y_Pos > tb.Top + tb.Height Then Exit Function

    InsideTextbox = True
    End Function
    [/vba]

    Paul

  4. #4
    VBAX Regular
    Joined
    Feb 2009
    Location
    Norfolk ( The English one)
    Posts
    24
    Location
    Paul / Mike Thanks for your input.All working, thx

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •