R
richard
Hi
I am trying to run an append query with criteria from a select box stored in
a form. However I am getting a run time error 3075 saying there are missing
operators.
This is my first conversion of an SQL statement into code so I am lost. Any
help appreciated
Private Sub Report_Close()
Dim qdf As DAO.QueryDef
Dim db As DAO.Database
Dim varItem As Variant
Dim strCriteria As String
Dim strAssistFMJobs As String
Dim stDocName As String
Dim ctrl As Control
Dim strSQL As String
Set db = CurrentDb()
Set ctrl = Forms!frmAssistFMDataSheetPrints.lstAssistFMJobs
Set qdf = db.QueryDefs("qrynapsworkappend")
For Each varItem In ctrl.ItemsSelected
strAssistFMJobs = strAssistFMJobs & "," & ctrl.ItemData(varItem)
Next varItem
If Len(strAssistFMJobs) = 0 Then
MsgBox "You did not select anything from the list", vbExclamation,
"Nothing to find!"
Exit Sub
End If
strAssistFMJobs = Mid(strAssistFMJobs, 2)
strSQL = "INSERT INTO tblnapsworkcheckbox ( siteref, BatchDate, BatchNumber,
Seperator )" & _
"SELECT tblnapswork.siteref, Now() AS expr2,
Nz(DMax([BatchNumber],[tblAssistFMSubJobNumbers]),0)+1 AS expr3,
tblAssistFMSubJobNumbers.Seperator " & _
"FROM tblnapswork INNER JOIN tblAssistFMSubJobNumbers ON
tblnapswork.jobnumber = tblAssistFMSubJobNumbers.JobNumber" & _
"WHERE tblAssistFMSubJobNumbers.Seperator In(" & strAssistFMJobs &
");"
qdf.SQL = strSQL
DoCmd.OpenQuery "qrynapsworkappend"
CurrentDb.Execute ("qrynapsworkupdate"), dbFailOnError
CurrentDb.Execute ("qrynapsworkdelete"), dbFailOnError
End Sub
I am trying to run an append query with criteria from a select box stored in
a form. However I am getting a run time error 3075 saying there are missing
operators.
This is my first conversion of an SQL statement into code so I am lost. Any
help appreciated
Private Sub Report_Close()
Dim qdf As DAO.QueryDef
Dim db As DAO.Database
Dim varItem As Variant
Dim strCriteria As String
Dim strAssistFMJobs As String
Dim stDocName As String
Dim ctrl As Control
Dim strSQL As String
Set db = CurrentDb()
Set ctrl = Forms!frmAssistFMDataSheetPrints.lstAssistFMJobs
Set qdf = db.QueryDefs("qrynapsworkappend")
For Each varItem In ctrl.ItemsSelected
strAssistFMJobs = strAssistFMJobs & "," & ctrl.ItemData(varItem)
Next varItem
If Len(strAssistFMJobs) = 0 Then
MsgBox "You did not select anything from the list", vbExclamation,
"Nothing to find!"
Exit Sub
End If
strAssistFMJobs = Mid(strAssistFMJobs, 2)
strSQL = "INSERT INTO tblnapsworkcheckbox ( siteref, BatchDate, BatchNumber,
Seperator )" & _
"SELECT tblnapswork.siteref, Now() AS expr2,
Nz(DMax([BatchNumber],[tblAssistFMSubJobNumbers]),0)+1 AS expr3,
tblAssistFMSubJobNumbers.Seperator " & _
"FROM tblnapswork INNER JOIN tblAssistFMSubJobNumbers ON
tblnapswork.jobnumber = tblAssistFMSubJobNumbers.JobNumber" & _
"WHERE tblAssistFMSubJobNumbers.Seperator In(" & strAssistFMJobs &
");"
qdf.SQL = strSQL
DoCmd.OpenQuery "qrynapsworkappend"
CurrentDb.Execute ("qrynapsworkupdate"), dbFailOnError
CurrentDb.Execute ("qrynapsworkdelete"), dbFailOnError
End Sub