Share via

Need help with OpenRecordset and SELECT statement

Anonymous
2012-11-08T18:56:04+00:00

In the code below, I'm receiving a Run-time error '3141':  The SELECT statement includes a reserved word or an argument name this is misspelled or missing, or the punctuation is incorrect.

The line causing the error is:  Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot), but as best as I can tell, my SQL statement is correct.

Can someone kindly tell me what is causing the error?  Thanks in advance for any assistance.

Private Sub PhaseDeliverableName_BeforeUpdate(Cancel As Integer)

    Dim db As DAO.Database

    Dim rs As DAO.Recordset

    Dim strResult As String

    Dim strSQL As String

    Set db = CurrentDb

    strSQL = "SELECT LookupPhaseDeliverable.PhaseDeliverableSequence AS SeqNum" & _

                  "FROM LookupPhaseDeliverable " & _

                  "WHERE (((LookupPhaseDeliverable.PhaseDeliverableName)=" & Me.PhaseDeliverableName & ";"

    Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)

    strResult = rs("SeqNum")    

    rs.Close

End Sub

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2012-11-08T20:31:17+00:00

There should be a space after SeqNum.

Is PhaseDeliverableName a text field? If so, it should be

    strSQL = "SELECT PhaseDeliverableSequence AS SeqNum " & _

        "FROM LookupPhaseDeliverable " & _

        "WHERE PhaseDeliverableName=" & Chr(34) & Me.PhaseDeliverableName & Chr(34)

Chr(34) is the double quote character ".

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2012-11-08T20:36:46+00:00

    Yes, PhaseDeliverableName is a text field.  I completely forgot about including the double quote character.  Thanks for also catching the missing space after SeqNum.

    The code now works like a charm!  Thanks again for your help.

    Was this answer helpful?

    0 comments No comments