syntax error? Help

K

Kate

I'm trying to execute an SQL statement in a macro attached
to a form but get error A RunSQL action requires an
argument consisting of an SQL statement. What is wrong?

Dim strSQL As String

strSQL = "SELECT AVAILABILITY.BookingDate,
AVAILABILITY.Period, AVAILABILITY.Room," _
& "AVAILABILITY.[Day Number], AVAILABILITY.[Booking ID] "
_
& "FROM AVAILABILITY " _
& "WHERE (((AVAILABILITY.BookingDate)=Forms![SINGLE
BOOKING AVAILABILITY]" _
& "!BookingDate) & ((AVAILABILITY.Period)=Forms![SINGLE
BOOKING AVAILABILITY]" _
& "!Combo8) & ((AVAILABILITY.Room)=Forms![SINGLE BOOKING
AVAILABILITY]!Combo10))"

DoCmd.RunSQL strSQL

SQL should look like this:

SELECT AVAILABILITY.BookingDate, AVAILABILITY.Period,
AVAILABILITY.Room, AVAILABILITY.[Day Number], AVAILABILITY.
[Booking ID]
FROM AVAILABILITY
WHERE (((AVAILABILITY.BookingDate)=Forms![SINGLE BOOKING
AVAILABILITY]!BookingDate) And ((AVAILABILITY.Period)
=Forms![SINGLE BOOKING AVAILABILITY]!Combo8) And
((AVAILABILITY.Room)=Forms![SINGLE BOOKING AVAILABILITY]!
Combo10));
 
R

RI

create your sql statemnt as a QUERY in design view and
then paste the sql where you need it
 
D

Douglas J. Steele

You can't use DoCmd.RunSQL with a SELECT statement: it's intended for Action
queries (DELETE, INSERT INTO, UPDATE)
 

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

Help me ! 4
Process records from a query 1
Put message to form 1
DoCmd.RunSQL error Help 5
Syntax error 1
Getting data from forms 2
Update not working 1
Using recordset I get errors 4

Top