简体   繁体   中英

Hide/unhide combobox based on a text box

I have a form in access that works in this way:

User select an ID of a product VBA code searches in the database and fill some textboxes in the form. For example: User select ID 1 Textbox 1 is filled with: fruit

My problem is, i have a combobox with options to select like "banana" or "apple" or "grape". This combobox is visible at the form, but i want it to be invisible and only appears if the textbox 1 is filled with "fruit".

In the design view, i set the combobox's visibility to "no", so it does not appear anymore in the form. Then, i wrote this code:

Private Sub textbox1_AfterUpdate()
  If Me.textbox1 = "fruit" Then
      Me.LabelOfTheCombobox.Visible = True
      Me.Combobox.Visible = True
  Else
      Me.LabelOfTheCombobox.Visible = False
      Me.Combobox.Visible = False
  End if
End Sub
    

But it doesnt work, when the textbox is filled with "fruit", the combobox remains invisible. Can you help me fix this code?

Everything looks OK. From what you have said, that putting "fruit" in the textbox doesn't cause the combobox to display, then my guess would be that the If-test is failing. Perhaps you could try trimming both sides of the textbox before the comparison. You should also pay attention to the case. Try forcing the case of the textbox to lower case to match the string constant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM