Code question re: incrementing a field.

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

Guest

The following code is giving me an error - Too Few Parameters. Expected 1.
I'm just trying to increment a field when a button is pushed.

strSQL = "UPDATE students " & _
"SET intSilLunch = intSilLunch + 1 " & _
"WHERE txtName = '" & Forms!frmSilTrans!cboName.Column(1) & "'"
Any thoughts? Thanks.

Nick
 
I assume that intSilLunch is a variable that has had its value set
previously in the code.

Anything within the quotes will simply be passed verbatim to strSQL. If you
want the VALUE of intSilLunch sent to strSQL you will need to take it out of
the quotes and concatenate it in. Also, add a space before the word WHERE.

strSQL = "UPDATE students " & _
"SET intSilLunch =" & intSilLunch + 1 & _
" WHERE txtName = '" & Forms!frmSilTrans!cboName.Column(1) &
"'"
Debug.Print strSQL

To see if the strSQL is getting what you are hoping it is getting, add a
Debug.Print after you set it. This will print the value of strSQL to the
Immediate Window. Look at what is printed, is it correct?
 
I put in your code but get the same error. intSilLunch is a field in the
table students.
 
Ok, you're wanting to update the value of a field in the table to one more
than its current value.

strSQL = "UPDATE students " & _
"SET intSilLunch = [intSilLunch] + 1 " & _
"WHERE txtName = '" & Forms!frmSilTrans!cboName.Column(1) &
"'"

You need to put backets around the second intSilLunch or it will be treated
as a string.
 

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

Similar Threads


Back
Top