conditional update of checkbox dependent on combo box in separate.

E

Emelina Bumsquash

I want to alter a checkbox from FALSE to TRUE based on the selection given in
a combo box. The combo box and checkbox are in different tables related by
the primary key (study number).

In the coding for the databse, there are currently SQL commands which insert
dates into target fields afterupdate of a 'date of randomisation' in a
separate table. One of them is coded something like the below:

SQL = "INSERT INTO TableA(Date1) VALUES ('" & DateOfRandomisation.Value + 30
& "') "
DoCmd.RunSQL SQL

SQL = "UPDATE TableA SET Date1 = '" & DateOfRandomisation.Value + 30 & "'
WHERE StudyNumber = "'"
DoCmd.RunSQL SQL

I didn't design this database or write this coding and I'm not particularly
expert but I think I should be able to copy the format of the coding above to
get, say the checkbox in TableA to be 'True' after update of a combo box.
However, I only want the checkbox value to turn to 'true' conditional upon
the particular choice made in that combo box i.e. if the combo box value is
2, THEN make the checkbox True rather than just indiscriminantly turning it
true.

any ideas? as i say i'm not an expert so plain english please! many thanks
for any help.
 
K

Klatuu

No need to worry about the SQL part. This is all done in Access. All you
need to do is use the After Update event of the combo box to set the check
box value.

Private Sub MyCombo_AfterUpdate()

With Me
If .MyCombo = 'Whatever value' Then
.MyCheckBox = True
Else
.MyChecBox = False
End If
End With

End Sub
 
E

Emelina Bumsquash

But what about when the combo box and checkbox are on different tables within
the same database, linked by the primary key, study number? thanks for your
speedy reply though!

PS i see 'me' used a lot in answers - is that just supposed to be substitued
with the name of the form / field in that persons database?
 
K

Klatuu

Are the two controls we are talking about bound controls or unbound controls?
If they are bound controls then you don't need to worry about it. If either
is an unbound control, then you would need to use SQL to update the record.

Me. or Me! can be used in forms and reports modules to reference the form
the module belongs to. It is just short hand for Forms!FormName.
The technically correct syntax is Me!
But most of us use Me. because it allows you to use Intellisense.
 
E

Emelina Bumsquash

now this is me being really thick but both the form controls (the combo box
and the checkbox in question) update fields in underlying tables once updated
(but again, these tables are separate and linked by primary key). does that
mean they are bound?

thank you for your helpful description of the 'Me!' thing. apologies for the
delay in replying.

Emma
 
D

DavidBoyle

Yes the controls that you describe are bound. Any control that when altered
changes the underlying data or which shows table data is bound. The bound
field is set in the controlsource property.

An unbound field will have no controlsource set, text boxes will show the
word "Unbound" at design time.

Unbound fields can be used to display un-editable data, for example you might
have a bound form that updates address1, address2 and address3 and then
programatically pass that data into an unbound field called address on a
different form.

Emelina said:
now this is me being really thick but both the form controls (the combo box
and the checkbox in question) update fields in underlying tables once updated
(but again, these tables are separate and linked by primary key). does that
mean they are bound?

thank you for your helpful description of the 'Me!' thing. apologies for the
delay in replying.

Emma
Are the two controls we are talking about bound controls or unbound controls?
If they are bound controls then you don't need to worry about it. If either
[quoted text clipped - 54 lines]
 

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