change check box value based on combo box value

D

DrONDeN

I have a form (Form1) with a combo box (Combo43) with three values:

Reference 1
Antenatal 1
Quant 1


I also have two check boxes (check36 and check34)


What is the best way to implement such that when Reference 1 is
selected in the combo box, check34 changes from false to true, and
when Antenenal 1 or quant 1 is selected, check 36 changes to true?
I've tried something along the lines of, but no luck:


Private Sub Combo43_AfterUpdate()
If Me.Combo43 = "Reference 1" Then
Me.Check32 = True
Else
Me.Check32 = False
End If
End Sub


I'm a beginner at this, so any help would be amazing. Thanks!
 
B

BruceM

It is best to describe exactly what did or did not happen. "No luck" is
vague.
You mention wanting to change Check34 and Check36, but your code references
Check32.
Are the check boxes bound controls? Are Check34 and Check36 always the
opposite of each other? I wonder if they are necessary at all. If you want
to have them for reference, they could be unbound controls.
More information is needed.
 
G

Guest

Try

Private Sub Combo43_AfterUpdate()

Me.Check32 = (Nz(Me.Combo43,"") = "Reference 1")
Me.Check36 = Not (Nz(Me.Combo43,"Reference 1") = "Reference 1")

End Sub
 
G

Guest

In Addition, the best is to get the resault using a query

Select TableName.* , IIf([FieldName]="Reference 1",True,False) As Check34
,IIf([FieldName]="Antenatal 1" Or [FieldName]="Quant 1",True,False) As
Check36 From TableName

Don't store this value in the table.
 
D

DrONDeN

BruceM

Combo box values are stored in a table (Boxes)
Check box values are stored in a seperate table (SampleData)

When 'Reference 1' is selected from the combo box, I want 'checkbox A'
to change from false to true.

When 'Quant 1' or 'Antenatal 1' is selected, I want 'checkbox B' to
change from false to true

When I inserted the code as mentioned before into the afterupdate
event, literally nothing happened. Ignore the checkbox numbers in the
code... they were for example only.

In the meantime, I will try the other solutions. Thanks guys.
 
B

BruceM

Do I understand correctly that when you select a value for Combo43 the value
is stored in the Boxes table, and that the check box values are stored in
the SampleData table? Are both of these table included in the form's record
source? Does the existing code compile correctly?
As I mentioned before, if the value of the Yes/No field can be dervived from
other data, the field is probably unnecessary.
 
G

Guest

Has anyone ever mentioned to you that check36, check36, and combo43 don't
mean a whole lot?

I strongly recommend that you change the name of your controls so that you
can actually tell what the checkbox, combobox, textbox actually does, or
refers to.

Dale
 

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