Show Text Box if Name is...

qwerty99

Registered User.
Local time
Today, 15:08
Joined
May 7, 2013
Messages
41
I feel like this should be a simple problem, but I'm still new to VBA and am having trouble figuring it out.

I have a form that has a text box giving some information, but I only want the text box to show if the account name is a specific name.

So if the account name is "Longhaul" then the text box should show in the form. If the name is anything else, the text box should not be visible

I have the following code:

<code>
If WCAccountName = "Longhaul" then
textBox.Visible = true
Else
textBox.Visible = false
end if
</code>

But since it is a text box there are limited ways in the property sheet to put in any code. "On Mouse Move" sort of works, but doesn't refresh when I change between records, and besides I feel like there should be a more efficient way of doing this.

Any help is appreciated!
 
Querty99

You do not say where your code is stored.

I would suggest you put it in the Form's On Current event and prefix control names with a reference to the form.

Code:
Private Sub Form_Current()
   If Me.WCAccountName = "Longhaul" Then
      Me.textBox.Visible = True
   Else
      Me.textBox.Visible = False
   End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom