Re: DoCmd.RunSQL error Help

From: fredg (fgutkind_at_example.invalid)
Date: 04/29/04


Date: Thu, 29 Apr 2004 22:16:40 GMT

On Thu, 29 Apr 2004 13:33:23 -0700, Kate wrote:

> 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));

RunSQL will only run Action queries.

Create a query using your SQL.
Then Run the query from your code event.
DoCmd.OpenQuery "QueryName"

-- 
Fred
Please only reply to this newsgroup.
I do not reply to personal email.


Relevant Pages

  • Re: Need help with WHERE
    ... dim strSQL as string ... get the SQL Text from the query qInsertAgentInfo ... post the SQL text of the query and I will have a look for you. ...
    (microsoft.public.access.formscoding)
  • Re: Cant edit corrupted query, "Syntax Error in FROM Clause"
    ... Dim strSQL As String ... but the query is not the problem. ... > different database. ... >>> I am developing an application in VB.NET that uses SQL queries to read ...
    (microsoft.public.access.queries)
  • Re: Insert Into SQL
    ... If you really want a book on SQL, "SQL for Mere Mortals" would be good ... Hopefully you are aware that you can build any query in the graphical query design window, and then switch to SQL View What I do is build the query there using any old criteria, and then copy it to the code window. ... You then have to concatenate the query into the string, adding the " quotes for Text fields or the # delimiter for Date fields. ... Dim strSql As String ...
    (comp.databases.ms-access)
  • Re: Delete button and refresh
    ... Just looking at your SQL I do see one problem. ... in a DELETE FROM query. ... Alex wrote: ... Dim strSQL As String ...
    (microsoft.public.access.formscoding)
  • Re: query filter
    ... You can modify a query by modifing the SQL property of the query. ... Dim strSQL As String ...
    (microsoft.public.access.gettingstarted)