Printing current record only from subform

N

nxg0hfst92q5cyp

Hi - I am trying to rewrite an audit database for herbal medicine
prescribing. I am having trouble getting a report to print correctly
from a button on a subform. The main form is called fm_entry and the
subform subfm_herbal_px. They are linked through a field called
[Hospital Number] (text field - it is not always a number despite the
name). The primary key for the subform is Px_ID (Autonumber). The
report is called rpt_px and takes its data from a query that
references the two tables that the forms are based on.

I have successfully written code that works if there is just one
record in the subform. However, if there is more than one record then
all records are printed rather than just the current one. Doing some
digging in the newsgroups has led me to the following code:

Private Sub cmd_print_px_Click()

Dim stDocName As String
Dim stWhere As String

Me.Dirty = False
stDocName = "rpt_px"
stWhere = "[Hospital Number] =" & Me.[Hospital Number] & " AND
Px_ID = " & Me.subfm_herbal_px.Form.Px_ID

DoCmd.OpenReport "rpt_px", , , stWhere

End Sub

But this trips on the second reference to [Hospital Number] where the
error message is 'Method or data member not found'. As I've cobbled
together the code I've probably done something pretty fundamental
wrong, but I am not skilled enough in Access to know what this is.

I would be very grateful if anyone could point me in the right
direction.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top