Connecting Tech Pros Worldwide Forums | Help | Site Map

Passing primary keys from form to form

Newbie
 
Join Date: May 2007
Posts: 24
#1: Jul 4 '07
Hi

I am having trouble with some forms i am creating for a database.

I have a data entry form at the moment that enters information into one table and a subform within the form that enters information into another table.

The subform takes the primary key, which is an autonumber, from the main form, as the subform puts information in a table which is linked to the table that the main form puts information into.

My problem is that I want to create a second form after this one, which i want to automatically take the primary key autonumber from the previous form.

Does anyone know the visual basic to do this?

Thanks

Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#2: Jul 5 '07

re: Passing primary keys from form to form


If the form is still open, you can use
Forms![Form Name]![Primary Key Field Name]

If not you can pass it in the open args paramenter of DoCmd.OpenForm
DoCmd.OpenForm "Form Name", , , , , , Me.[Primary Key Field Name]
Newbie
 
Join Date: May 2007
Posts: 24
#3: Jul 11 '07

re: Passing primary keys from form to form


Thanks for the reply.

It works if the form is still open.

However, I need it to work with the first form closed as when i click to open the second form, it enters the data from the first form (so all the fields then go blank as the data has been entered) and so there is nothing left in the field on the first form for the field in the second form to take.

Basically I need to be able to store the value that appears in a text box on one form and get it to appear in another text box on the second form.

Can anyone help?

ps. I'm sorry if i am asking obvious questions but I am a novice at access and I am still trying to understand a lot of it.
Newbie
 
Join Date: May 2007
Posts: 24
#4: Jul 11 '07

re: Passing primary keys from form to form


I read the posting guidelines, replace "field" in my messages with "textbox"
Rabbit's Avatar
Expert
 
Join Date: Jan 2007
Location: California
Posts: 3,835
#5: Jul 11 '07

re: Passing primary keys from form to form


Use the second method I provided.
Then in your form, you can get the value using Me.OpenArgs
Reply