Results 1 to 5 of 5
  1. #1
    broecher is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Sep 2010
    Posts
    38

    my first DoCmd.RunSQL

    Not sure what I am doing wrong here, this gives me the error "The RunSQL action requires an argument consisting of an SQL statement":



    Option Compare Database

    Public Sub test1()

    Dim strSQL As String

    strSQL = "SELECT AttributeList.Id " & _
    "FROM AttributeList;"

    DoCmd.RunSQL strSQL

    End Sub


    Tried it again with no variables. with quotes, no quotes, parenthesis...


    Option Compare Database

    Public Sub test1()

    DoCmd.RunSQL "SELECT AttributeList.Id FROM AttributeList;"

    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    RunSQL can only be used with an action query (append, update, make table). If you're trying to display records to the user, I'd use a form or report (you can set the source of either to your SQL).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    broecher is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Sep 2010
    Posts
    38
    ohhhh, thanks

    I am not sure what I should do now. Actually my goal is to make a 'master' query that will serve as the main data source for several other queries. The original data table is a xml memo field.

    Below is the start of what I was really trying to do. It didn't work either of course. So for something like this, I should use a report? will i be able to query the results?


    Option Compare Database

    Public Function sightins3()




    Dim Elem(6)

    Elem(1) = "4764F5E6-15A1-48BF-808A-F673ED7CDCDA"
    Elem(2) = "EB86279A-E032-43D2-B4A8-8B8B2892B10E"
    Elem(3) = "7AF84421-802B-482F-A83B-BCDB2C49BB1D"
    Elem(4) = "0CCFA54A-683D-4709-963B-FB4B4805BD6B"
    Elem(5) = "51C4E220-73F0-4C11-ACB1-E7B7DE75731F"
    Elem(6) = "855C31A2-27C9-454A-985B-9911D7CFAB42"

    For i = 1 To 6

    strSQL = 'strSQL& IIf(InStr([XmlData], '&Elem(i)&' )=0, ' &_
    ' "False",Mid([XmlData],InStr(InStr([XmlData], '&Elem(i)&' ),[XmlData],"Value=") ' &_
    ' +7,InStr(InStr(InStr([XmlData], '&Elem(i)&' ),[XmlData],"Value=")+7,[XmlData],"/>") ' &_
    ' -InStr(InStr([XmlData], '&Elem(i)&' ),[XmlData],"Value=")-8)) AS '&Elem(i)&' , '

    Next i

    strSQL = strSQL& 'FROM Sighting2;'

    DoCmd.RunSQL '"SELECT " & strSQL'


    End Function

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    to help Paul here, two things you should know about what you posted. first, an array has a 0-base. so, your loop will skip the first element in the array and when i reaches 6, it'll throw an error because there will be no element for array(6). the upper bound will be (5). second, your loop is overwriting the sql everytime it goes through, so if you're looking to do something with each 'i' that you loop through, you're only going to get a result for the last loop, and the sql is going to run with that. the first 4 or 5 (until it errors) will be overwritten.

    the other thing is that I don't think strings it vba can be indicated by single quote marks. I may be wrong, but something to consider.

    just a few facts for you.

  5. #5
    broecher is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Sep 2010
    Posts
    38
    thank you very much Paul and Adam

Please reply to this thread with any new information or opinions.

Similar Threads

  1. docmd.runsql update
    By Mitch_Aus in forum Programming
    Replies: 2
    Last Post: 10-05-2010, 09:45 AM
  2. Email sent via DoCmd.SendObject
    By silverback in forum Programming
    Replies: 0
    Last Post: 10-29-2009, 06:26 AM
  3. Problem with DoCmd.RunSQL
    By Peter01 in forum Programming
    Replies: 2
    Last Post: 09-10-2009, 07:11 PM
  4. docmd.runsql not working
    By Rameez in forum Programming
    Replies: 3
    Last Post: 08-07-2009, 10:07 AM
  5. DoCmd.SendObject Help
    By bgreer5050 in forum Programming
    Replies: 0
    Last Post: 01-12-2007, 06:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums