Yes, assuming the button is on a form bound to the table (or to a query) and
you want to open the report for the current record, in the button's Click
event procedure you'd first save the record, and then open the report,
filtering to the record with the same primary key value as the current record
in the WhereCondition argument of the OpenReport method.
I'm guessing you've used the control wizard to set up the button, in which
case the code for its Click event would be something like this:
On Error GoTo Err_cmdOpenReport_Click
Dim stDocName As String
stDocName = "MyReport"
DoCmd.OpenReport stDocName, acPreview
Exit_cmdOpenReport_Click:
Exit Sub
Err_cmdOpenReport_Click:
MsgBox Err.Description
Resume Exit_cmdOpenReport_Click
You'd change it to:
On Error GoTo Err_cmdOpenReport_Click
Dim stDocName As String
Dim stCriteria As String
stDocName = "MyReport"
stCriteria = "[MyID ]= " & Me.[MyID]
' save current record
Me.Dirty = False
' open report in print preview
' filtered to current record
DoCmd.OpenReport stDocName, _
View:=acPreview, _
WhereCondition:=strCriteria
Exit_cmdOpenReport_Click:
Exit Sub
Err_cmdOpenReport_Click:
MsgBox Err.Description
Resume Exit_cmdOpenReport_Click
Where MyReport is the report's name and MyID is the primary key field of the
form's and report's underlying recordsets. This assumes MyID is a number
data type. If its text data type you'd wrap its value in quotes characters
with:
stCriteria = "[MyID ]= """ & Me.[MyID] & """"
Ken Sheridan
Stafford, England
Hi
I'm a bit confused at this point. Do I put this into the code for my print
button or do I put it somewhere else? So far I haven't written any code for
my forms.
Thanks
One other thing: before calling the OpenReport method (with the
WhereCondition argument restricting it to the current record) make sure that
[quoted text clipped - 17 lines]