Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New England (Connecticut)
    Posts
    200
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi all,

    At the risk of looking very stupid, can anyone tell me why the following generates an error stating that to run it requires an argument consisting of an sql statement?


    Dim dbCurr As DAO.Database
    Dim rs As DAO.Recordset
    Dim mySQL As String
    Set dbCurr = CurrentDb

    mySQL = "SELECT PIIN " & _
    "FROM Cams_Piin_Data1 " & _
    "WHERE PIIN_CODE = '" & Me![PIIN_CODE] & "';"


    DoCmd.RunSQL mySQL




    Any help would be appreciated.

    Thank You
    Kevin

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    DoCmd.RunSQL is intended to execute an SQL statement for an action query, i.e. the SQL statement must begin with UPDATE, SELECT ... INTO, INSERT INTO or DELETE. It can not be used with the SQL for a SELECT query.

    I see that you declare a recordset variable but don't do anything with it. Perhaps you want to open a recordset on the SQL statement? Code would be

    Set rs = dbCurr.OpenRecordset(mySQL, dbOpenDynaset)

  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    [quote name='mcneilkm' post='791165' date='29-Aug-2009 01:50']Hi all,

    At the risk of looking very stupid, can anyone tell me why the following generates an error stating that to run it requires an argument consisting of an sql statement?


    Dim dbCurr As DAO.Database
    Dim rs As DAO.Recordset
    Dim mySQL As String
    Set dbCurr = CurrentDb

    mySQL = "SELECT PIIN " & _
    "FROM Cams_Piin_Data1 " & _
    "WHERE PIIN_CODE = '" & Me![PIIN_CODE] & "';"


    DoCmd.RunSQL mySQL




    Any help would be appreciated.

    Thank You[/quote]
    The DoCmd.RunSQL command is used for an action query, eg INSERT, UPDATE etc.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •