stephengrenfell
Registered User.
- Local time
- Tomorrow, 00:11
- Joined
- Jul 1, 2009
- Messages
- 19
Hello,
I have a VBA script that selects records from the table tblInv where the value of tblInv.InvSendEmail=True and then sends the value of InvNum to the rptInv for each selected record.
I am a bit bogged down with the SQL syntax. I get an Error 3131 "syntax error in FROM clause.."
Any help apprciated.
Thanks.
Here is the code:
Private Sub cmdPrintInvoices_Click()
' Error handler
On Error GoTo cmdPrintInvoices_error
Dim rst As DAO.Recordset
Const PrintInvoiceQuery As String = "SELECT [InvNum]" & "FROM tblInv" & "WHERE tblInv.InvSendEmail=True"
' Get a recordset using the query
Set rst = CurrentDb.OpenRecordset(PrintInvoiceQuery, dbOpenSnapshot)
' Move through the recordset looking at each record
With rst
Do While Not .EOF
' Open report.
DoCmd.OpenReport "rptInv", acViewNormal, , "InvNum = ![InvNum]"
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
exit_cmdPrintInvoices_error:
Exit Sub
cmdPrintInvoices_error:
MsgBox "Error " & Err & "." & Chr(13) & Chr(10) & Chr(10) & Err.Description & ".", vbExclamation
Resume exit_cmdPrintInvoices_error
End Sub
I have a VBA script that selects records from the table tblInv where the value of tblInv.InvSendEmail=True and then sends the value of InvNum to the rptInv for each selected record.
I am a bit bogged down with the SQL syntax. I get an Error 3131 "syntax error in FROM clause.."
Any help apprciated.
Thanks.
Here is the code:
Private Sub cmdPrintInvoices_Click()
' Error handler
On Error GoTo cmdPrintInvoices_error
Dim rst As DAO.Recordset
Const PrintInvoiceQuery As String = "SELECT [InvNum]" & "FROM tblInv" & "WHERE tblInv.InvSendEmail=True"
' Get a recordset using the query
Set rst = CurrentDb.OpenRecordset(PrintInvoiceQuery, dbOpenSnapshot)
' Move through the recordset looking at each record
With rst
Do While Not .EOF
' Open report.
DoCmd.OpenReport "rptInv", acViewNormal, , "InvNum = ![InvNum]"
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
exit_cmdPrintInvoices_error:
Exit Sub
cmdPrintInvoices_error:
MsgBox "Error " & Err & "." & Chr(13) & Chr(10) & Chr(10) & Err.Description & ".", vbExclamation
Resume exit_cmdPrintInvoices_error
End Sub