Help with for each

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am use to writing vb in excel and i am unsure in Access
I want to set value of all records in fild to a text box value where check box value is true
i am trying
Dim ctl as control 'unsure if correct or what it really means
for each ctl in form.controls 'as above
i am ok with this part
next ctl
Thanks
Tina
 
I would recommend an Update Query to do this. You can run the query from
code and it'll be much faster than dealing with the controls on the form or
stepping through each record.

The way you are going would step through each control on a form. Assuming
single form view, you would have one record displayed at a time and you
would step through each control/field for that record. I'm guessing that
what you're wanting to do is update a particular field or fields when the
value of another field is True (checked) and that you want to do this for
each record.

Update query example:

UPDATE Table1 SET Table1.Field1 = 55
WHERE (((Table1.Field2)=True));

This could be run from code as:

CurrentDb.Execute "UPDATE Table1 SET Table1.Field1 = 55 WHERE
Table1.Field2=True;", dbFailOnError
 
Back
Top