DoCmd.RunSQL error Help

From: chris (anonymous.chris_at_mercury-projects.co.nz.discussions.microsoft.com)
Date: 04/29/04


Date: Thu, 29 Apr 2004 14:34:43 -0700

RunSQL only works with action queries (insert, update
delete etc) that do not return recordset objects. A select
query needs a recordset object to store its results
>-----Original Message-----
>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));
>
>.
>



Relevant Pages

  • Re: Help with Docmd.RunSql Please
    ... RunSQL is for action queries. ... If you want to examine the results programmatically, use OpenRecordset(). ... If you want to view the results on screen, use OpenQuery. ...
    (microsoft.public.access.formscoding)
  • Re: DoCmd.RunSQL not working
    ... DoCmd.RunSQL is used to run action queries, ... Use DoCmd.OpenQuey instead for your query. ... I am receiving, " A RunSQL ... > action requires an argument consisting of an SQL statement". ...
    (microsoft.public.access.queries)
  • Re: Select SQL in VBA - Possible
    ... RunSQL is used to run Action queries, ... Private Sub CreateMovementRecords_Click ... This SQL is just copied from the SQL view of the query that works fine ...
    (microsoft.public.access.gettingstarted)
  • Re: DoCmd.RunSQL
    ... RunSQL can only work with Action queries. ... Dim Passw As String ... Exit Sub ...
    (microsoft.public.access.modulesdaovba)