2
votes

My database has several tables to split up the large number of attributes for a report.

I have created a series of Forms to enter data with a "Next" button which closes the form and opens the next.

How do I pass the primary key between forms? I want it to auto-populate so that the user doesn't have to re-type it on every form.

EDIT: Each form corresponds to a single table. The entry for that table/form doesn't exist until "Next" is clicked on that form.

1
You could achieve the same result neatly by using a main form and several subforms in the several tabs of a tab control. The subforms could then be kept in sync with the main form without any programming.Patrick Honorez

1 Answers

1
votes

Use the WhereCondition with Docmd.OpenForm. (See OpenForm Method)

So if your next form is named frmTwo, the primary key field is named ID, and the current form has a control named txtID which contains the value you want to pass to the next form:

DoCmd.OpenForm "frmTwo", WhereCondition:="ID = " & Me.txtID

That suggestion assumes ID is numeric data type. If it's text, you would have to enclose the Me.txtID value with quotes when building the WhereCondition.

Edit: I didn't understand your situation clearly. Not sure I do now, either, but I suspect the easiest "code-free" solution would be to use a main form with your subsidiary forms as subfrom controls. Then by setting the link Master/Child fields property you can automagically transmit the primary key value to new records in the various subforms.

If the number of subsidiary forms is large, you can include them as separate pages in a tab control on the main form.

That approach is something Access does well and easily, without requiring extra VBA code or macros.