Enable Textboxes Based on Combo Box Valve

  • Thread starter pushrodengine via AccessMonster.com
  • Start date
P

pushrodengine via AccessMonster.com

I have a form called “frmIncidentFormâ€. Within this form I would like to
disable all of the controls expect for a Combo Box called “Typeâ€. Then when
the user selects a value the form will enable the textboxes that are required
for that specific Type.

For example, when the user selects “Check The Welfare†form the “Type†Combo
Box,

AddIncident is Enabled
Date is Enabled
Medic is Enabled
Time1008 is Enabled
Time 1097 is Enabled

On the other hand, if the user selects “Dry Runâ€.

AddIncident is Enabled
Medic is Enabled
Time1148 is Enabled
Time 1098 is Enabled

Thanks
 
T

tina

you can write a procedure to enable/disable the controls, and then call that
procedure from the combobox control's AfterUpdate event procedure, and from
the form's Current event procedure. there are a number of ways to write the
setup procedure, for instance:

Private Sub ControlsSetup()

With Me
!AddIncident.Enabled = (!Type = "Check The Welfare" _
Or !Type = "Dry Run")
!Date.Enabled = (!Type = "Check The Welfare")
!Medic.Enabled = (!Type = "Check The Welfare" _
Or !Type = "Dry Run")
!Time1008.Enabled = (!Type = "Check The Welfare")
!Time1097.Enabled = (!Type = "Check The Welfare")
!Time1148.Enabled = (!Type = "Dry Run")
!Time1098.Enabled = (!Type = "Dry Run")
End With

End Sub

and then call the procedure, as

Private Sub Type_AfterUpdate()

ControlsSetup

End Sub

it's easier to put the code in one procedure, and then call that procedure
wherever you need to in the form, than to write the code separately in each
event procedure where it needs to run.

as for the code itself, what i wrote above are simple "toggle" expressions.
Access evaluates the expression on the "right" side of the first equal (=)
sign to True or False. the True or False value is then used as the setting
for the property named on the "left" side of the first equal (=) sign. note
that if you have a lot of options to choose from in the combobox's droplist,
the above code could get cumbersome; another approach might be easier to
write and maintain, in that case.

also, i notices that you have two "time" fields for "Check The Welfare", and
two *different* time fields for "Dry Run". if you're storing the same type
of data (date/time values?) in both groups of fields, i have to wonder if
you may have an underlying issue with normalization in your table(s)
structure.

hth
 
P

pushrodengine via AccessMonster.com

The code works great, except when a value is entered than deleted I get an
error “Run-time error ‘13’ Type mismatch.

How can I fix this?

Thanks
 
P

pushrodengine via AccessMonster.com

Sorry Correction:

The code works great, except when a value is entered then deleted I get an
error “Run-time error ‘13’ Type mismatch.

How can I fix this?
 
T

tina

sorry i didn't get back to you yesterday, but you found the solution on your
own - very good, you always learn more that way! and you're welcome. :)
 

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