WalksWithSky
Instructor
Hello, all:
I have created the following code attached to a command button on a form to print out a report in Word. The code works great (source is the FAQ703-760 by Telsa -- thanks heaps!) in that it sends everything to Word where it is supposed to go. The problem I am having is passing the ReportID value from the current record on the form to the code.
Here’s the code on the button now:
The only problem is the code is locked onto ReportID 1. The FAQ suggested this instead:
This is what I would like, for the code to grab the current ReportID, but when I tried it, the following error was produced:
The error is occurring on this line of code:
ReportID is an AutoNumber field in the table. Does that
matter, or make a difference? As well, on the form, the ReportID text box is hidden. Does that matter?
Any help anyone can provide with this would be great. The rest of the code works fine when I lock in a ReportID value, but when I ask it to get the value from the form, then it halts at that line of code.
Thanks in advance (and thanks to Telsa for an awesome FAQ!)
Walks With Sky
I have created the following code attached to a command button on a form to print out a report in Word. The code works great (source is the FAQ703-760 by Telsa -- thanks heaps!) in that it sends everything to Word where it is supposed to go. The problem I am having is passing the ReportID value from the current record on the form to the code.
Here’s the code on the button now:
Code:
Private Sub Command65_Click()
Dim db As DAO.Database
Dim recReview As DAO.Recordset
Dim strSQL As String
strREPORTID = Me.ReportID
strSQL = "SELECT * FROM qryReports WHERE ReportID = 1 "
Set db = CurrentDb()
Set recReview = db.OpenRecordset(strSQL)
CreateReview recReview
End Sub
The only problem is the code is locked onto ReportID 1. The FAQ suggested this instead:
Code:
Dim db As DAO.Database
Dim recReview As DAO.Recordset
Dim strSQL As String
strREPORT = Me.ReportID
strSQL = "SELECT * FROM qryReports WHERE ReportID = ‘ " & strREPORT & ‘ " ;"
Set db = CurrentDb()
Set recReview = db.OpenRecordset(strSQL)
CreateReview recReview
End Sub
This is what I would like, for the code to grab the current ReportID, but when I tried it, the following error was produced:
Code:
Run-time Error ‘3464’
Data type mismatch in criteria expression
The error is occurring on this line of code:
Code:
strSQL = "SELECT * FROM qryReports WHERE ReportID = ‘ " & strREPORT &‘ ";"
ReportID is an AutoNumber field in the table. Does that
matter, or make a difference? As well, on the form, the ReportID text box is hidden. Does that matter?
Any help anyone can provide with this would be great. The rest of the code works fine when I lock in a ReportID value, but when I ask it to get the value from the form, then it halts at that line of code.
Thanks in advance (and thanks to Telsa for an awesome FAQ!)
Walks With Sky