Running an "If...Then..." to set a field value for each record in adatasheet

R

RMTechie

In datasheet view, I want to set the value of a checkbox to true if
the value of a combo box in a datasheet is equal to a certain value
("Single").

How do I do this for each record?
 
D

Dale Fye

Well, the simplist way to do it is to run a query when you load your form.

After that, I'd use the AfterUpdate event of the combo box with code similar
to:

Private Sub me.cbo_Whatever_AfterUpdate

me.chk_Whatever = iif(me.cbo_Whatever = "Single", True, False)

End Sub

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
R

Ron2006

1) this implies that there are two fields in your table indicating the
same thing, which is not usually a good idea in a normalized table
because of the logic of trying to keep them synchronized.

That said.

A) create an update query that
updates the checkbox filed to True
has criteria that says that the combobox field is equal to
"Single" (or is equal to the key of the table used for the combo if
that is what is stored instead of the value "Singel".

B) In the form that is used to update the records.
In the afterupdate of the combofield have
if me.comboboxfieldname = "Singel" then
me.checkboxfieldname = true
else
me.checkboxfieldname = false
endif

C) In that same form IF you have the checkbox as an updatable field
in the afterupdate of the checkboxfield have
if me.checkboxfield = true then
me.comboboxfieldname = "Single"
else
(this is the tricky part and you will have to think
about what would be the best value for this. This is why having two
fields sort of showing the same thing is not a good idea.)
me.comboboxfieldname = null
endif.

Ron
 
R

Ron2006

The fact that it is bound says that the logic I just gave you will
work regardless of whether this is continuous, or single, or datasheet
view.

Ron
 

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