I wish to run a report for a specific criteria. I get an error message on the DoCmd.OpenReport command. The error message states "The expression is typed incorrectly or it is too complex to be evaluated".
The query referenced (qry_general_letter) is based on another query which is based on a table. It is the data source for the report specified in the OpenReport command.
Is the syntax incorrect?
Or does the Where clause of the OpenReport function not allow a query based upon a query?
DoCmd.OpenReport "rpt_General_Letter", acViewPreview, "", "[qry_General_Letter].[transaction number] = """ & strTransNo & """"
Below is surrounding code:
sql = "SELECT [Leave Bank Transaction Log].[transaction number], [Leave Bank Transaction Log].[transaction code], " _
& "[Leave Bank Transaction Log].VLtype FROM [Leave Bank Transaction Log]" _
& " WHERE " _
& "([Leave Bank Transaction Log].[transaction number]>=" & [Forms]![frm_letter_generation]![begintrans] & "
" _
& " And ([Leave Bank Transaction Log].[transaction number]<=" & [Forms]![frm_letter_generation]![endtrans] & "
" _
& " AND ([Leave Bank Transaction Log].[transaction code]=""GC""
" _
& " AND ([Leave Bank Transaction Log].VLtype=""VLBP""
;"
Set CheckForRecords = CurrentDb.OpenRecordset(sql, DB_OPEN_DYNASET)
With CheckForRecords
If .RecordCount > 0 Then
Do While Not .EOF
strTransNo = .Fields("[Transaction Number]"
DoCmd.OpenReport "rpt_General_Letter", acViewPreview, "", "[qry_General_Letter].[transaction number] = """ & strTransNo & """"
.MoveNext
Loop
MsgBox "General Contribution Letters Completed"
Else
' MsgBox "No data selected for general contribution letters."
.Close
End If
End With
The query referenced (qry_general_letter) is based on another query which is based on a table. It is the data source for the report specified in the OpenReport command.
Is the syntax incorrect?
Or does the Where clause of the OpenReport function not allow a query based upon a query?
DoCmd.OpenReport "rpt_General_Letter", acViewPreview, "", "[qry_General_Letter].[transaction number] = """ & strTransNo & """"
Below is surrounding code:
sql = "SELECT [Leave Bank Transaction Log].[transaction number], [Leave Bank Transaction Log].[transaction code], " _
& "[Leave Bank Transaction Log].VLtype FROM [Leave Bank Transaction Log]" _
& " WHERE " _
& "([Leave Bank Transaction Log].[transaction number]>=" & [Forms]![frm_letter_generation]![begintrans] & "
& " And ([Leave Bank Transaction Log].[transaction number]<=" & [Forms]![frm_letter_generation]![endtrans] & "
& " AND ([Leave Bank Transaction Log].[transaction code]=""GC""
& " AND ([Leave Bank Transaction Log].VLtype=""VLBP""
Set CheckForRecords = CurrentDb.OpenRecordset(sql, DB_OPEN_DYNASET)
With CheckForRecords
If .RecordCount > 0 Then
Do While Not .EOF
strTransNo = .Fields("[Transaction Number]"
DoCmd.OpenReport "rpt_General_Letter", acViewPreview, "", "[qry_General_Letter].[transaction number] = """ & strTransNo & """"
.MoveNext
Loop
MsgBox "General Contribution Letters Completed"
Else
' MsgBox "No data selected for general contribution letters."
.Close
End If
End With