Re: DoCmd.RunSQL error Help

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


Date: Fri, 30 Apr 2004 00:11:47 GMT

On Thu, 29 Apr 2004 16:15:54 -0700, Kate wrote:

> Trouble with that is I then want to test a field (Booking
> ID) in the returned record and I get an error message
> Object required. Any thoughts
>
>>-----Original Message-----
>>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.
>>.
>>

You can use a DLookUp() in a form control to find any particular
record in the query (without actually running the query).
See Access help for
DLookUp and
Where clause + restrict data to a subset of records.

In any event, you CANNOT run a Select query using RunSQL.

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


Relevant Pages

  • Re: Im struggling with my limited knowledge of code
    ... he couldn't advise how to handle a query with parameters. ... BookingID, as SingleBooking, etc. ... >Private Sub Command14_Click ... It doesn't work because AVAILABILITY. ...
    (microsoft.public.access.formscoding)
  • Re: Im struggling with my limited knowledge of code
    ... he couldn't advise how to handle a query with parameters. ... BookingID, as SingleBooking, etc. ... >Private Sub Command14_Click ... It doesn't work because AVAILABILITY. ...
    (microsoft.public.access.gettingstarted)
  • Re: Im struggling with my limited knowledge of code
    ... he couldn't advise how to handle a query with parameters. ... BookingID, as SingleBooking, etc. ... >Private Sub Command14_Click ... It doesn't work because AVAILABILITY. ...
    (microsoft.public.access.queries)
  • Re: Im struggling with my limited knowledge of code
    ... he couldn't advise how to handle a query with parameters. ... BookingID, as SingleBooking, etc. ... >Private Sub Command14_Click ... It doesn't work because AVAILABILITY. ...
    (microsoft.public.access.macros)
  • Re: how do i?
    ... The DLookup fixed it. ... John Spencer wrote: ... If you want to display the value of TheDateField in the query result, ... George Applegate wrote: ...
    (microsoft.public.access.queries)