newcomer seeks help on passing on table values

  • Thread starter Thread starter fb
  • Start date Start date
F

fb

I have recently started programming Access VBA and my goal is to create one
table that relates to a second table. the first table will contain a record
specifying a company and the second one will be linked to contain
responsible persons with their address,.....

My goal is to enter the company using a form and, if there will be a new
responsible partner click a button to open a second f orm for the second
table to enter all the new persons there. This would work, except that I
have not yet found out how to pass on the primary key from my 1st table e.g.
to the second table so I can generate a relationship without having to type
in the number.

I have tried to understand the pass on forms discussion in this newsgroup,
but failed.

My other problem is, in theory I thought I might access the databae as
tabledef fields and thought I would then get the value, but I have not even
succeeded to run the VBA help examples.

Any help would be kindly appreciated and is badly needed
 
This is most easily done with a subform on your main form and the link
master/child properties set to the primary key from the company table.
However, if you want to open another form, you can use the OpenArgs
functionality:
Code in main form
Docmd.OpenForm "frmPersons",acNormal,,,acFormAdd ,acDialog,Me.CompanyID
Then, in the on open form of frmPersons, use code like:
If Len(Me.OpenArgs & "") >0 Then
Me.CompanyID.DefaultValue = Me.OpenArgs
End If
 
I have recently started programming Access VBA and my goal is to create one
table that relates to a second table. the first table will contain a record
specifying a company and the second one will be linked to contain
responsible persons with their address,.....

My goal is to enter the company using a form and, if there will be a new
responsible partner click a button to open a second f orm for the second
table to enter all the new persons there. This would work, except that I
have not yet found out how to pass on the primary key from my 1st table e.g.
to the second table so I can generate a relationship without having to type
in the number.

You're making this harder than it needs to be!

Access has a very convenient and commonly used tool for just this
purpose: a Subform. Put the form bound to the People table onto the
Company form as a Subform, using the Primary Key as the "Master Link
Field" and the foreign key field as the "Child Link Field". No code,
no buttons, no special handling needed.

If you don't have screen space for the subform, you can put the
existing controls on one page of a Tab Control and the subform on a
second tab.

If you really want to pop up a form, it can be done with a bit of
code; post back if that's what you want, though in practice the
Subform is easiest for both the developer and the user.
 
Back
Top