Open Form From Form With Selected Record

Exodus

Registered User.
Local time
Today, 07:12
Joined
Dec 4, 2003
Messages
317
I have a tab form to search for polls locations. Each tab uses differrent criteria to search in sub forms. this all works fine. The problem I'm running into is I want to open a seprate form that will put the PPID automaticly.

I use a before insert event to do this the problem is I don't know how to write it so if pulls the PPID from the sub form that called it to open.
 
You can use the FilterName or WhereCondition parameters of the DoCmd.OpenForm method to open the form with the PPID you want. You can even use the OpenArgs parameter if that's better for you.

Why are you using the Before Insert event of the form? If you must pull the value from that other form you just opened, the way to refer to the value from the original form's subform would be something like:
Forms("original_form_name")("Subform_Name")("subform_control_name")
or
Forms!original_form_name!subform_name.Form!subform_control_name
 
dcx693,

ok tried the following code
DoCmd.OpenForm "PhoneContactTracking", , , Forms!FindPolls!PollingPlacesResults.Form!PollID

It doesn't populate the field. Ive tried it in open args and where condition.
The form is for data entry does this matter.

I was using the before insert event based on a search of the forum. I believe it was Pat who suggested cuz she doesn't like to dirty the record unless the user does. Also for less confusion for the user.
 
Is it a text field? I have had similar problems that were fixed when I did:
DoCmd.OpenForm "PhoneContactTracking", , , Forms!FindPolls!PollingPlacesResults.Form!PollID.Text
 
Unfortunately it is a number field.
Thanks for the reply.
 
"MyField = " & CLng(Forms!FindPolls!PollingPlacesResults.Form!PollID)
 
Ok I'm Using

DoCmd.OpenForm "PhoneContactTracking", , , "PPID = " & CLng(Forms!FindPolls!PollingPlacesResults.Form!PollID)

Sorry to say it's not working. What am I doing wrong?
 
Are you pulling this value direct from the database or is it being stored in a textfield?
 
Um not sure?
Ok here is what I'm doing.
The PollID from the selected record on the subform to the PPID on the newly opened PhoneContactTracking from.

The PollID field is the unique idenifier in the database, it is a number field Long integer.

What I want is for the Form PhoneContactTracking when opend to have the PPID atoumancticly imputed. PPID is a number field. Then the user can imput the rest of the data. What I'm trying to do is to kind of idiot proof the system so the user won't screw up by miss keying the wrong PollID.
 
Last edited:
Got it Working here is the Code

DoCmd.OpenForm "PhoneContactTracking", acNormal, "", "", acAdd, acNormal
Forms!PhoneContactTracking!PPID = Forms!FindPolls!PollingPlacesResults!PollID
 
Your method dirties the new form whether a record is actually added with it or nor. Your original idea of using the BeforeInsert event won't do that.

Change the OpenForm Method so that it passes the value using the openargs.

DoCmd.OpenForm "PhoneContactTracking", acNormal, , , acAdd, acNormal, Me.PollID

Then in the BeforeInsert event in your new form:
Me.PPID = Me.OpenArgs

FYI, it is better practice to use the same name for the foreign key field as you used for it's related primary key field.
 
Hi Pat,

I agree Idon't want to dirty the record until the user does. As far as the nameing of the foriegn, I agree also, I'am going to change it.

Tried the
DoCmd.OpenForm "PhoneContactTracking", acNormal, , , acAdd, acNormal, Me.PollID

Error Menber not found On Me.PollID


I'm thinkin Its because the PollID is on the Sub form just a guess. I'm not very knowledgeable about code. So if I reference the Subform then I have to reference the subform in the Berfore insert event right?
which brings me back to my original problem. My Main form is a tab form. Each tab has it's own subform to display the results of a search. Is it possible to look to more than one subform in the Berfore insert event?
 
Thanks Pat,
I guess I should have thouroughly thought that one out.
Thats just what I'm lokking for.
Many thanks and Much Apprciation. :D
 

Users who are viewing this thread

Back
Top Bottom