Skip to content
Advertisement

Run-time Error 3131 Syntax Error in FROM clause

Tried scouring the forums for threads similar to mine but couldn’t really find anything that would lead me in the right direction. Basically I have a table that has the QA scores for each of the 10 regions and I am trying to populate a text box with a specific region’s score depending on the month. I was trying to do this in vba for this form but came across this Run-time error 3131 and I’m not entirely sure what’s wrong with my code which seems simple enough to me. Thanks for any help or advice in advance.

Private Sub Form_Load()


Dim strSql As String


strSql = "SELECT tblScorecard.[QA_Overall]" & _
        "FROM tblScorecard" & _
        "WHERE tblScorecard.[Audit Month] = 'Jan'" & _
        "AND tblScorecard.[Region] = '1'"

DoCmd.RunSQL strSql

txtReg1 = strSql

End Sub

Advertisement

Answer

Is it not possible you should just add spaces? tblScorecard.[QA_Overall]FROM as one word?

Private Sub Form_Load()


Dim strSql As String


strSql = "SELECT tblScorecard.[QA_Overall] " & _
        "FROM tblScorecard " & _
        "WHERE tblScorecard.[Audit Month] = 'Jan'" & _
        " AND tblScorecard.[Region] = '1'"

DoCmd.RunSQL strSql

txtReg1 = strSql

End Sub

In order to avoid Error: 2342 A RunSQL:

Private Sub Form_Load()
    Dim qdf As QueryDef
    strSql = "SELECT tblScorecard.[QA_Overall] " & _
        "FROM tblScorecard " & _
        "WHERE tblScorecard.[Audit Month] = 'Jan'" & _
        " AND tblScorecard.[Region] = '1'"
    On Error Resume Next
    DoCmd.DeleteObject acQuery, "tempQry"
    On Error GoTo 0
    Set qdf = CurrentDb.CreateQueryDef("tempQry", strSQL)
    DoCmd.OpenQuery ("tempQry")
End Sub

More information found here.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement