RunSQL asking for a parameter

B

Brian

I have a form with a button that executes some code which
amongst other things includes:

MsgBox varNewID
strSQL = "Update AVAILABILITY " & _
"Set AVAILABILITY.[Booking ID] = varNewID " & _
"WHERE AVAILABILITY.BookingDate=#" & _
Forms![SINGLE BOOKING AVAILABILITY]!BookingDate & _
"# And AVAILABILITY.Period=" & Forms![SINGLE
BOOKING AVAILABILITY]!Combo8 & _
" And AVAILABILITY.Room=""" & Forms![SINGLE
BOOKING AVAILABILITY]!Combo10 & """"
DoCmd.RunSQL strSQL

I get a popup box asking 'Enter a parameter value'
VarNewID. Why? The message before the strSQL shows that
varNewID contains a value such as 77.

What have I got wrong? Thanks.
 
D

DebbieG

At quick glance it looks like you're missing the " & before varNewID.

"Set AVAILABILITY.[Booking ID] = " & varNewID & _

HTH,
Debbie


I have a form with a button that executes some code which
amongst other things includes:

MsgBox varNewID
strSQL = "Update AVAILABILITY " & _
"Set AVAILABILITY.[Booking ID] = varNewID " & _
"WHERE AVAILABILITY.BookingDate=#" & _
Forms![SINGLE BOOKING AVAILABILITY]!BookingDate & _
"# And AVAILABILITY.Period=" & Forms![SINGLE
BOOKING AVAILABILITY]!Combo8 & _
" And AVAILABILITY.Room=""" & Forms![SINGLE
BOOKING AVAILABILITY]!Combo10 & """"
DoCmd.RunSQL strSQL

I get a popup box asking 'Enter a parameter value'
VarNewID. Why? The message before the strSQL shows that
varNewID contains a value such as 77.

What have I got wrong? Thanks.
 
J

John Spencer (MVP)

Answered elsewhere. You need to get the value of varNewID into the query
string. The SQL query does not recognize the VarNewID as a variable. So change
the second line of your query string as follows

strSQL = "Update AVAILABILITY " & _
"Set AVAILABILITY.[Booking ID] =" & varNewID & _
"WHERE AVAILABILITY.BookingDate=#" & _
Forms![SINGLE BOOKING AVAILABILITY]!BookingDate & _
"# And AVAILABILITY.Period=" & _
Forms![SINGLE BOOKING AVAILABILITY]!Combo8 & _
" And AVAILABILITY.Room=""" & _
Forms![SINGLE BOOKING AVAILABILITY]!Combo10 & """"
 

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

Using recordset I get errors 4
Update not working 1
Passing parms to a query? 1
Why doesn't this update work? 5
Why no update? Help! 2
DoCmd.RunSQL error Help 5
syntax error? Help 2
No rows returned. Help! 1

Top