PDA

View Full Version : Need help to disable fields based on a user selection frm combo box?



keek2a4
03-05-2008, 04:42 AM
Hi,

I have a dropdown list that queries a table and displays the dropdown list on the form. I want to write a vba code that based on
the selection the user makes on the dropdown, it disables some text fields on the form, so user cannot enter a value.

I am thinking of using a After event procedure and my logic is


If me.comboBoxName.count = 1 Then ' how can I write what value is selected from the dropdown
me.textfield1.disable = true
me.textfield2.disable = true
End If



Is there a better way of doing it? I am not too sure on the correct syntax on this one. Please help!

Thanks,

orange
03-07-2008, 10:08 AM
Hi,

I have a dropdown list that queries a table and displays the dropdown list on the form. I want to write a vba code that based on
the selection the user makes on the dropdown, it disables some text fields on the form, so user cannot enter a value.

I am thinking of using a After event procedure and my logic is


If me.comboBoxName.count = 1 Then ' how can I write what value is selected from the dropdown
me.textfield1.disable = true
me.textfield2.disable = true
End If


Is there a better way of doing it? I am not too sure on the correct syntax on this one. Please help!

Thanks,
I'm not sure exactly what you are asking, but here is my interpretation.

You have a Form with a combobox that has a query as a recordsource.
Depending on the selection from this combobox, you want to disable some other controls on the form.

When I have done something similar, I use the control.visible = False option. I think the AfterUpdate event is correct.

eg.
If

dpf44
03-08-2008, 07:44 AM
This may depend on your data source, but you should be able to get the key field for your combo box using me.comboBoxName.Value and the text associated with the key using me.comboBoxName.Text .

At the very least the quick example I threw together in Access allowed me to retrieve the data in this way. I used the following simple Query as my RowSource:


SELECT Data.ID, Data.Data FROM Data ORDER BY [Data];

This, combined with the response from Orange, should hopefully help you solve your problem.