Optional field

lzfy

Registered User.
Local time
Today, 03:41
Joined
May 12, 2010
Messages
13
First of al my apologies if this has been asked before but I couldn't find any solution for this problem. I have a form with a listbox with multiple items (Let's say A,B,C,D). When I choose A or B, I want to show a field below the listbox, but if I choose C or D, then the field should not be displayed. The attached screenshot should make it more clear.

Thanks.
 

Attachments

  • field.png
    field.png
    2.1 KB · Views: 108
1. that isn't a listbox. It is a combo box.

2. in the After Update event of the combo you can use

Code:
Me.YourTextBoxNameHere.Visible = (Me.ComboBoxNameHere In("A", "B"))
 
I see, thanks for the clarification :)

I changed the code like this

Code:
Me.BegindatumHH.Visible = (Me.invoervak92 In("CIZ"))

"BegindatumHH" is the textfield name and "invoervak92" is the combo box name. When I paste this code in the after update field of the combo box, I get an error saying that it can't find the object "Me". I know I'm doing it wrong :D but I can't find out wat.
 
You appear to be putting it in the Event PROPERTY and not in the VBA window where it needs to go. See this for how to get to the VBA window and place it in the appropriate event (the sample shows a different event so don't let that confuse you).
 
Hi there. I didn't want to create a new topic so I'm asking it here (hope that's ok). I'm trying to disable a field with a checkbox, with the following code:

Code:
Private Sub Actief_AfterUpdate()
If Actief = "Yes" Then
klnr.Enabled = True
Else
klnr.Enabled = False
End If
End Sub
I can disable the field with this code, but after that I can't re-enable it. Anyone knows what the problem is?
 
Your test is wrong. It should not be testing for "YES" in quotes. But instead:

Code:
Private Sub Actief_AfterUpdate()
If Actief = True Then
   klnr.Enabled = True
Else
   klnr.Enabled = False
End If
End Sub

And in fact you can make it one line of code:
Code:
Private Sub Actief_AfterUpdate()

   klnr.Enabled = Actief

End Sub
 
Your test is wrong. It should not be testing for "YES" in quotes. But instead:

Code:
Private Sub Actief_AfterUpdate()
If Actief = True Then
   klnr.Enabled = True
Else
   klnr.Enabled = False
End If
End Sub
And in fact you can make it one line of code:
Code:
Private Sub Actief_AfterUpdate()

   klnr.Enabled = Actief

End Sub

Thank you so much B L, I really appreciate your help. There's only one problem though. When I close the form and reopen it, the field is enabled again. I tried to put the same code on before update but that didn't help.
 
Just add this to the form's Current event:

Code:
Private Sub Form_Current()
   Actief_AfterUpdate
End Sub
 

Users who are viewing this thread

Back
Top Bottom