Print specific record in subform

Falcondeer

New Member
Joined
Apr 5, 2021
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi everybody

I am new to this forum and almost not very expert in ms access,

I have a db for my physiotherapy store where I have a main form and a subform, I have the following code for the command button to print a record in the subform:

Dim strReportName As String
Dim strCriteria As String
strReportName = "rptWA2"
strCriteria = "P_ID= " & Nz(Me!P_ID, 0)
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

The problem now if I have more than one record in the subform, it will always print the first record no matter what .

Now, how could I print specific record in the subform.

Thanks.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
When there is more than one record, are you selecting the record you want first? If not, you'll get the first record.
If so, step through your code and see what strCriteria holds after that line has been executed (i.e. step to DoCmd but no further before mousing over strCriteria to see what it contains). As long as the record that is current (selected) is not a new record, what you have should work. If it is a new record, you'll have to save it first.
 
Upvote 0
A record in your main form has some identifier. Also related records in your subform have an identifier that matches the identifier in your main form.
What is the other field/control that separates the 2 (or more) records in the subform??

I think you're looking for something beyond strCriteria = "P_ID= " & Nz(Me!P_ID, 0) that also identifies the subform record you want to report.
Could be newestDate; largest/smallest Amount.......????
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top