enable fields on a form based on input in a field

G

Guest

I am a rank amateur at this so please be as specific as possible.

I made a form to enter data from different types of permits. I want to
disable certain fields on the form based on the option chosen in a combo box
on the form.

The form name is enter_new_permit
the combo box is combo16
the database is permits.mdb

The different options on the combo are "eup_air_conditioner",
"eup_refrigeration", and "marquee".

I am using access 2003

Thanks in advance
 
D

Damon Heron

In design view, select the combo16 properties. Find the afterupdate event.
click on (...) to go to vb window. add this code in the afterupdate event:
(this is assuming your combobox items are a value list)

Select Case combo16.text
Case "eup_air_conditioner"
me.text1.enabled= false
'list your controls you want disabled for this selection
Case "eup_refrigeration"
me.text2.enabled=false
etc.
Case "marquee"
etc.
case else
msgbox "Please make a selection", vbOKOnly

End Select

Next, you have to enable the controls you disabled for a new record. So,
find the form property "on current" - click the (...), and add the
following:

me.text1.enabled= true
etc.
Substitute your control names for the textboxes in my example.


HTH
Damon
 
D

Damon Heron

In haste, I reversed the enabled vs. disabled. You probably want to have
all controls, with the exception of the combobox DISABLED upon entering a
new record. Then, based on the selection in the combobox, enabled the
applicable ones.

Damon
 
C

Carl Rapson

Washington Square Mark said:
I am a rank amateur at this so please be as specific as possible.

I made a form to enter data from different types of permits. I want to
disable certain fields on the form based on the option chosen in a combo
box
on the form.

The form name is enter_new_permit
the combo box is combo16
the database is permits.mdb

The different options on the combo are "eup_air_conditioner",
"eup_refrigeration", and "marquee".

I am using access 2003

Thanks in advance

Click on combo16 and open its Properties window. Click on the Events tab and
select [Event Procedure] for the After Update event. Click on the button
with three dots at the far right of the After Update line, and when the code
window opens, add code something like this between the Public Sub
combo16_AfterUpdate() and End Sub lines:

Select Case combo16
Case "eup_air_conditioner"
' Enable/disable whatever fields you want here
Case "eup_refrigeration"
' Enable/disable whatever fields you want here
Case "marquee"
' Enable/disable whatever fields you want here
End Select

Save and close the code window and then test your form. If the selection
from combo16 is being saved in your database (is the combo box bound to a
field in the table?), you'll also need to add similar code to the
Form_Current event so that the controls are disabled/enabled whenever a
record is displayed.

Carl Rapson
 
G

Guest

YOU ROCK!

Damon Heron said:
In haste, I reversed the enabled vs. disabled. You probably want to have
all controls, with the exception of the combobox DISABLED upon entering a
new record. Then, based on the selection in the combobox, enabled the
applicable ones.

Damon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top