Opening a report from a button on a subform

  • Thread starter John S. Ford, MD
  • Start date
J

John S. Ford, MD

I have a main form frmPatients with a subform sbfPatientAppointment. The
main form contains general information about a patient and the subform
contains information from a particular visit (appointment) with that that
patient.

The underlying table for the subform contains a primary field
PatientVisitIDNum.

I want to place a command button cmdPrintVisit on the subform and have it
open a report that is based ONLY on the information on the visit being
worked on (of the patient reflected in the main form). In other words, I
want to filter the report's underlying query to limit it only to the
PatientVisitIDNum of the visit being worked on.

I'm assuming I can use the DoCmd.OpenReport method using the wherecondition
argument where wherecondition = "PatientVisitIDNum =
currentPatientVisitIDNum". How do I populate the currentPatientVisitIDNum
with the correct value?

Any ideas?

John
 
A

Allen Browne

Concatenate the value of the control into the WhereCondition string:

Dim strWhere As String
If Me.Dirty Then Me.Dirty = False
If Me.NewRecord Then
MsgBox "Select a visit to print."
Else
strWhere = "PatientVisitIDNum = " & Me.PatientVisitIDNum
Docmd.OpenReport "Report1", acViewPreivew, strWhere
End If

Explanation:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
 
J

John S. Ford, MD

Allen,

PatientVisitIDNum is an autonumber not a value placed into a TextBox. It is
created everytime a new visit is begun.

Can I access that field from Me.PatientVisitIDNum?

John
 

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