I have not done any work in Access for about 8 years and have been tasked with creating a simple form with a button to print the data on the form to a report. I have a print button on my form with this code behind.
I want to report to print 1 record but for some reason it is printing all of the records in the database. When I put a break point on the code the strWhere parameter is showing the correct ID number for the report.
Can anyone see what I am not getting here? How can I print the 1 record?
Code:
Public Sub PrintReport()
Dim strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "rptDispatchCard", , , strWhere
End If
End Sub
Can anyone see what I am not getting here? How can I print the 1 record?