Below is a line of code that works:
DoCmd.OpenReport "rpt_General_Letter", acViewPreview, , "[transaction number] = 8"
I would like to use a variable name instead of hardcoding as follows:
DoCmd.OpenReport "rpt_General_letter", acViewPreview, , "[transaction number] = strTransNo"
I have tried a variety of syntax structures, with the current code it produces a parameter box asking for the value of strTransNo.
In the Main Module, strTransNo is declared as a Public variable.
What is the proper systax for substituting a variable name instead of an actual value?
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""
" _
& " ORDER BY [Leave Bank Transaction Log].[transaction number];"
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, , "[transaction number] = strTransNo"
.MoveNext
Loop
MsgBox "General Contribution Letters Completed"
Else
MsgBox "No data selected for general contribution letters."
.Close
End If
End With
DoCmd.OpenReport "rpt_General_Letter", acViewPreview, , "[transaction number] = 8"
I would like to use a variable name instead of hardcoding as follows:
DoCmd.OpenReport "rpt_General_letter", acViewPreview, , "[transaction number] = strTransNo"
I have tried a variety of syntax structures, with the current code it produces a parameter box asking for the value of strTransNo.
In the Main Module, strTransNo is declared as a Public variable.
What is the proper systax for substituting a variable name instead of an actual value?
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""
& " ORDER BY [Leave Bank Transaction Log].[transaction number];"
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, , "[transaction number] = strTransNo"
.MoveNext
Loop
MsgBox "General Contribution Letters Completed"
Else
MsgBox "No data selected for general contribution letters."
.Close
End If
End With