Runtime error 3131

Ravi Kumar

Registered User.
Local time
Today, 09:58
Joined
Aug 22, 2019
Messages
162
hello all ,

this code is giving me runtime error 3131:"Syntax error in from clause".
can anyone please tell me how to solve this..
Code:
Private Sub cmddept_Click()
   Dim RS As DAO.Recordset
    Dim strMsg As String
    
    Set RS = CurrentDb.OpenRecordset("select * from (" & Me.RecordSource & ")", dbOpenSnapshot, dbReadOnly)
    
    With RS
        If Not (.BOF And .EOF) Then
            .MoveFirst
            While Not .EOF
                If ![Position] >= 1 Then
                  strMsg = strMsg & ![Coil Number] & vbTab & vbTab & ![Position] & vbTab & vbCrLf
                End If
                .MoveNext
            Wend
        End If
        .Close
    End With
    Set RS = Nothing
    If strMsg <> "" Then
       strMsg = "You have to Calibrate the following!!!:" & vbCrLf & vbCrLf & _
"------------------------------------------------------------" & vbCrLf & _
"Coil Number" & vbTab & vTab & "Position" & vTab & vbTab & vbCrLf & _
"------------------------------------------------------------" & vbCrLf & _
strMsg
Else
strMsg = "No record to is due for calibration"
End If
    
    MsgBox strMsg, vbInformation + vbOKOnly
End Sub
i am using this code show a notification if my position column is updated to 1,then 1st column "coil number" & second column is "position" both should show .
 
Does RecordSource have an SQL statement? This statement will have a semi-colon at end which will error because it is within parens of the VBA concatenated string.

Try:
Set RS = CurrentDb.OpenRecordset(Me.RecordSource, dbOpenSnapshot, dbReadOnly)

If the RecordSource is simply a table or query name, are there spaces or special characters in name?

Show what exactly is in RecordSource property.
 
Last edited:
Start with some basics.
Build your sql statements into strings, then you can Debug.Print the string to see what it actually contains. not what you think it contains.

Save a LOT of time.
 

Users who are viewing this thread

Back
Top Bottom