event procedure to open new form

snorf3

Registered User.
Local time
Today, 14:11
Joined
May 25, 2001
Messages
45
I have a subform that displays a list of records based on a query. I'd like to double-click the "Name" field and have that result in the opening of a different form, "frmPhysician", but to that specific record.

Basically, I want: double-click --> open frmPhysician --> goto [Name] record

What kind of code do I need to put in the event procedure for the On Double Click property? I'm a very early beginner to code! Thanks for all your help in advance.

[This message has been edited by snorf3 (edited 06-12-2001).]
 
Thanks Pat! I looked it up in help but I still have another question. The help doesn't say much about the OpenArgs section. What exactly am I supposed to put there? This is what I have so far...It doesn't run as is...it says there is a "Compile Error: Expected: ="
-------------------------------------------
Private Sub Health_Care_No_DblClick(Cancel As Integer)

DoCmd.OpenForm (frmPhysician,acFormDS,[OpenFrmPhysician],[Health_Care_No]=Form![Active Patient List subform]![Health_Care_No],acFormEdit,acWindowNormal)

End Sub
-------------------------------------------
As you can see, I want to click on the Health_Care_No field of a subform and have that open the frmPhysician of that specific patient.

Thanks for your help so far!
 
This works for me....

Private Sub TreatmentDate_DblClick(Cancel As Integer)


On Error GoTo Err_TreatmentDate_DblClick

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Customer_Treatment_Detailed"
stLinkCriteria = "[TreatmentID]=" & Me![TreatmentID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_TreatmentDate_DblClick_:
Exit Sub

Err_TreatmentDate_DblClick:
MsgBox Err.Description
Resume Exit_TreatmentDate_DblClick_


End Sub


*** if you copy and past that in, remember to miss of the opening private sub & end sub.
The stLinkCriteria is the criteria which you open the form with - i.e. in my case open it new form with the TreatmentID where it equals the TreatmentID from this form ( Me![TreatmentID]

Hope that helps.
 
forgot to say - they way i woked this out ( I'm new too - day 2 of Access ) is that i put a command button on my form and set it up to open a new form when pressed ( through the wizard ) Then I grabbed the code, placed it in the double-click field i actually wanted to open the new form ( remembering to change the private_sub name thoughout the code so it matched.

Bit of a cheat, but it worked !!

Good luck
 
Thanks Philip! That almost does the trick. One more thing yet!

Now when I double click on the name, I get a message box asking me to "Enter Parameter Value", and displays the name I just clicked on as the message.

It works if I then type in the exact same name as the one displayed. Is there any way to skip this step so it goes straight from the double click to the open form, without having to "enter parameter value"?
 
Make sure in the line
stLinkCriteria = "[TreatmentID]=" & Me![TreatmentID]

that the field name after Me! is the exact field NAME of the control that contains the information you want.

Check the control's name in the property window.

~Charity
 
Thanks, Charity! Unfortunately, I did enter my field name properly so I don't think that's the problem ... My field name is "Last_Name" and here is the code I have entered. It matches what you suggested, doesn't it? I'm still getting those "parameter value" message boxes. Is there something I can change in this code?


Private Sub Last_Name_DblClick(Cancel As Integer)

On Error GoTo Err_Last_Name_DblClick

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmPhysician"
stLinkCriteria = "[Last_Name]=" & Me![Last_Name]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Last_Name_DblClick_:
Exit Sub

Err_Last_Name_DblClick:
MsgBox Err.Description
Resume Exit_Last_Name_DblClick_

End Sub
 
If last_name is a text value you need to change the line

stLinkCriteria = "[TreatmentID]=" & Me![TreatmentID]

to

stLinkCriteria = "[TreatmentID]=" & Me![TreatmentID] & "'"

and is the form you are opening based on a query with any criteria? It sounds to me like you are filtering and querying the form.

Let me know

~Charity
 
I made the change (adding & "'")and now I get an error message saying:

Syntax error in string in query expression '[Last_Name]=Jones".

Jones being the name that I doubleclicked on.

The form I am trying to open is based on a table but only displays select fields from that table. It then has a subform in it that is based on a second table. The two are linked by a single ID number. There are no filters set up in my database and these forms are not based on any queries. Hope this is the info you need and thanks so much for your help in this!
 
Sorry about the syntax error, line should be:

stLinkCriteria = "[Last_Name]='" & Me![Last_Name] & "'"

I fixed a similar problem for someone else, and he was using a listbox to select the last name. If this is also the case with you, you need to reset the listbox value to "" before closing the lookup form.

me![Last_Name}=""



[This message has been edited by charityg (edited 06-14-2001).]
 
Excellent!!! Everything works perfectly now. Thanks for everything, Charity!
 

Users who are viewing this thread

Back
Top Bottom