Command Buttons and Forms

G

Guest

I hope someone can help me with this. I have two forms. One form has the
Doctors info and patients assoc to this doc. The second form has the
patients info and lists the docs assoc with pt. On my doc form I have a
command button to go to pt form and vice versa. This works fine. But when
the pt form open up, I have to search for the pt's name. Instead, I would
like to take this a bit further. I want to be able to be on the doc form,
put my cursor on a patient, click on the command button to go to pt form and
have the form go to that pt's record. Can someone please guide me as how to
do this? thank you in advance for any help will be greatly appreciated.
 
G

Graham Mandeno

It depends on whether you want to open the patients form filtered to show
ONLY the selected patient, of showing ALL the patients with the focus
INITIALLY on the selected patient.

To show only the selected patient, use the WhereCondition argument of
OpenForm:

DoCmd.OpenForm "frmPatients", WhereCondition:="PatientID=" & PatientIDValue

To show all patients with the initial focus on the selected one, use
OpenArgs:

DoCmd.OpenForm "frmPatients", OpenArgs:=PatientIDValue

Then, in your patients form's Form_Load procedure:

If Not IsNull(Me.OpenArgs) Then
With Me.RecordsetClone
.FindFirst "PatientID=" & Me.OpenArgs
If Not .NoMatch Then Me.Bookmark = .Bookmark
End With
End If

Note that I'm assuming your Patients table has a numeric primary key named
"PateintID".

PatientIDValue is the value of the selected patient's PatientID. This could
be Me!PatientID (from the subform) or Me.sbfDocPatients.Form!PatientID (from
the main form) if your docs form has the pts showing in a subform, or it
could be Me!lstDocPatients if the pts are listed in a listbox on the docs
form.
 
A

Arvin Meyer [MVP]

I'll do one of them. Change the names for the other:

I'll assume that the Doctor's form has the Patients in a subform, use the
Double-Click event of the subform:

Sub Form_DblClick(Cancel As Integer)
DoCmd.OpenForm "OtherFormName",,,"PatientID =" &
Me.SubformName.txtPatientID
End Sub
 
U

UpRider

Totally,
Your code to open the patient form should look like this:

DoCmd.OpenForm "frmPatients",,,"LastName = " & chr$(39) & me.txtPatLast &
chr$(39)

This assumes that your form name is frmPatients and that 'LastName' is a
field in that form's recordsource
and txtPatLast is the name of the textbox holding the patient last name on
the CURRENT (calling) form.
Modify to match your names.

HTH, UpRider
 

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