On-Click Event Code

galvinjaf

Registered User.
Local time
Today, 17:27
Joined
Jan 5, 2016
Messages
108
Good Afternoon,

I've attached the following code to my On_Click event, however, it's not working the way I intended. When the form loads, it makes all of my Serial Number fields visible whereas I only want them visible if the drop down box has selected equipment highlighted. If I go into the field, select equipment, and then delete it manually, my serial number field goes away and works. How can I make this code work, but have the form also check those fields when it loads?

Code:
 Private Sub Equipment_1_Click()
If Me.Equipment_1 = "Headset" Or _
Me.Equipment_1 = "Dial Pad Box" Or _
Me.Equipment_1 = "Other" Then
Me.Serial_Number_1.Visible = True
Else
Me.Serial_Number_1.Visible = False
End If
End Sub

When my form loads, (pic attached) it's showing the serial number field, even though I told the code to only show that field if there is equipment selected.
 

Attachments

  • Equipment.JPG
    Equipment.JPG
    15.9 KB · Views: 115
It's a continuous form, so you are setting the visibility for all records for that control.
You need to use conditional formatting to hide / show things on continuous forms.
 
the click event is not fired until you click on the equipment control so you need to set your serial number control visible property to false in design view (or the open event if using vba)

And I think your code needs to be in the afterupdate event of the equipment control - to give the user a chance to select something.

Finally, if this is a continuous form, the visible setting will affect all serial number controls on the form. You may want to investigate using conditional formatting instead, you cannot set visibility but you can disable or set colours so it blends into the background
 
I agree that afterupdate of the text box is a better place to run the code. If the form is bound and it is not known which record will be displayed on form open, a call can to the afterupdate event can be placed in the form Load event, ie
Call Equipment_1_Afterupdate
 
After playing with the code, along with your advice, I was successfully able to get my form to work in a more agreeable way! I find this forum VERY helpful! Thank you!
 

Users who are viewing this thread

Back
Top Bottom