I found these procedures on how to create a command button to print just one record.
Followed them religously, but the button still prints all the records.
The steps
Private Sub cmdPrint_Click()
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 = "[ClientID] = " & Me.[ClientID]
DoCmd.OpenReport "client 3", acViewPreview, strWhere
End If
End Sub
The second problem is that I created a second button, set up the properties identically to print a different Report "Intake 4".
All I changed was the DoCmd.OpenReport to "Intake4",
When I do this, it changes the original button to "Intake4" also.
How do I fix both problems?
Followed them religously, but the button still prints all the records.
The steps
- Open your form in design view.
- Click the command button in the toolbox (Access 1 - 2003) or on the Controls group of the Design ribbon (Access 2007 and 2010), and click on your form.
- If the wizard starts, cancel it. It will not give you the flexibility you need.
- Right-click the new command button, and choose Properties. Access opens the Properties box.
- On the Other tab, set the Name to something like: cmdPrint
- On the Format tab, set the Caption to the text you wish to see on the button, or the Picture if you would prefer a printer or preview icon.
- On the Event tab, set the On Click property to: [Event Procedure]
- Click the Build button (...) beside this. Access opens the code window.
- Paste the code below into the procedure. Replace ID with the name of your primary key field, and MyReport with the name of your report.
Private Sub cmdPrint_Click()
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 = "[ClientID] = " & Me.[ClientID]
DoCmd.OpenReport "client 3", acViewPreview, strWhere
End If
End Sub
The second problem is that I created a second button, set up the properties identically to print a different Report "Intake 4".
All I changed was the DoCmd.OpenReport to "Intake4",
When I do this, it changes the original button to "Intake4" also.
How do I fix both problems?