By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Passing primary keys from form to form

P: 24

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?

Jul 4 '07 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 10K+
P: 12,335
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]
Jul 5 '07 #2

P: 24
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.
Jul 11 '07 #3

P: 24
I read the posting guidelines, replace "field" in my messages with "textbox"
Jul 11 '07 #4

Expert Mod 10K+
P: 12,335
Use the second method I provided.
Then in your form, you can get the value using Me.OpenArgs
Jul 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.