Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto complete checkbox based on selection from combo box 1

Status
Not open for further replies.

frosty2000

Technical User
Feb 5, 2005
18
US
Hello,

I am using a form to track employee benefit selections. In my form, I have a combo box where the user can select the name of the medical plan enrolled (i.e. Medical Gold, Medical Silver, or Medical Declined). I then have a checkbox titled "Medical Coverage" that I want to automatically check if the "Medical Gold" or "Medical Silver" is selected. (If left blank or if "Medical Declined" is selected, I want the box to remain unchecked.)

I would like the checkbox to automatically update the moment the plan is selected from the combo box. Also, once I get the checkbox working properly, I would like to hide the checkbox on the form, since it is populated automatically.

Any ideas on how to auto update the checkbox and then hide the checkbox? I'm new to programming, so I'm hoping the fix is something simple! Thanks for your help!

frosty2000
 
How are ya frosty2000 . . . . .

In the [blue]AfterUpdate[/blue] event of the combobox, copy/paste the following ([blue]you![/blue] substitute proper names in [purple]purple[/purple]):
Code:
[blue]   If Me![purple][b]ComboboxName[/b][/purple].Column(0) <> "Medical Declined" Then
      Me![purple][b]CheckBoxName[/b][/purple] = True
   Else
      Me![purple][b]CheckBoxName[/b][/purple] = False
   End If[/blue]
You may have to play with the [blue]column number[/blue] of the combobox to get it right.

For the [blue]CheckBox[/blue], set the [blue]Visible[/blue] property to [purple]No[/purple].

Calvin.gif
See Ya! . . . . . .
 
Thanks for pointing me in the right direction, AceMan!

I put the following code into the AfterEvent update of the combo box, but I'm getting a "Runtime Error 424 Object Required" error when I open the form and select a medical plan from the combo box. When I debug, it's the first line of code that's highlighted in yellow.

Private Sub Medical_Plan_AfterUpdate()
If MedicalPlan.Column(0) <> "Medical Declined" Then
EmployeeMedicalCoverage = True
Else
EmployeeMedicalCoverage = False
End If
End Sub

Also, I need to add in another line (maybe a nested IF THEN statement?) to also turn the EmployeeMedicalCoverage checkbox to True when MedicalPlan combobox is not equal to "". I'm not sure exactly how to do this?

Help! Again, I haven't done VB since college, so I'm a beginner. What am I doing wrong? Thanks again for all your help!

 
Private Sub Medical_Plan_AfterUpdate()
[Medical Coverage] = ([Medical Plan] <> "Medical Declined" And Trim([Medical Plan] & "") <> "")
End Sub


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
frosty2000 . . . . .

Try changing Column([blue]0[/blue]) to Column([blue]1[/blue])!

Calvin.gif
See Ya! . . . . . .
 
Thanks to everyone for their help. Here's the code I used, and it seems to be working for me...

Private Sub MedicalPlan_AfterUpdate()
If [MedicalPlan] <> "Medical Declined" Then
[EmployeeMedicalCoverage] = True
Else
[EmployeeMedicalCoverage] = False
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top