• VBA Select Query

    Author
    Topic
    #462173

    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

    Viewing 1 reply thread
    Author
    Replies
    • #1175370

      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)

    • #1175472

      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

      The DoCmd.RunSQL command is used for an action query, eg INSERT, UPDATE etc.

    Viewing 1 reply thread
    Reply To: VBA Select Query

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: