Turniing on a check box

G

Guest

Hi,
I have a continuous form with the following fields from one table:

Name (text)
Grade (text)
CkMailingLabel (check box)

The form also has a combo box named cboGrade and a command button

Based on the grade selected in the cboGrade box I want to turn on (check)
the check box CkMailingLabel for the records where cboGrade = Grade

I currently have the following code in the command button which gives me an
error “too few parametersâ€

CurrentDb.Execute "UPDATE Students SET CkMailingLabel = -1 WHERE Grade =
cboGrade"

In my code the above line is on one line.

What am I missing or is there a better way?

Thanks
 
S

Steve Schapel

Phil,

Like this...
CurrentDb.Execute "UPDATE Students SET CkMailingLabel = -1 WHERE Grade
= '" & Me.cboGrade & "'"
(assumes Grade is a text field)

Mind you, the CkMailingLabel might already be set to -1 for some of the
records based on an earlier Grade selection, so you may also need to put
a line like this in first...
CurrentDb.Execute "UPDATE Students SET CkMailingLabel = 0"

As for "is there a better way", it depends what you are trying to
achieve. If, as I am guessing, the purpose is to "flag" records for
inclusion in a report, then probably your approach is more complicated
than it needs to be. It would be easier to simply base the report on a
query that directly references the cboGrade as a Criteria for the Grade
field, and forget the CkMailingLabel.
 
G

Guest

Your SQL needs to fully qualify the reference to your combo. It doesn't know
what it is. It also has to be outside the quotes otherwise, it will be sent
to Jet as the literal cboGrade and not the value:

CurrentDb.Execute "UPDATE Students SET CkMailingLabel = -1 " _
& "WHERE Grade = '" & Forms!MyFormName!cboGrade & "';"

The syntax above assumes Grade is a text field. If it is a numeric field,
do it this way:
CurrentDb.Execute "UPDATE Students SET CkMailingLabel = -1 " _
& "WHERE Grade = " & Forms!MyFormName!cboGrade & ";"
 

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