Copy ID

S

Swagener

Hi ,
I have a main form where new records are added, one of those fields is
a autonumber which is a primary key. The user will fill out all the
fields and open the next form which is bound to a different table but
has a Foreign key of the last table (which will be blank as its a new
record in the main table) , i can't figure out how to copy the id from
the first form and paste it onto the next form in the foreign key field

on openevent.

Thanks,
Riq
 
S

Swagener

Sorry i know what you mean .

I think had multiple explorer windows running .
so must have done that by mistake .!!

Can you help?
 
B

Brian Bastl

Swagener,

One way is to pass the PK value using the OpenArgs of the OpenForm command,
and assigning it to the appropriate control in the On Load event of the
'Other' form.

***on main form***
'save record
If Me.Dirty Then
Me.Dirty = False
End If

DoCmd.OpenForm "OtherForm" , , , , , , Me.MyPK

*** load event on called form***
If Not IsNull(Me.OpenArgs) Then
Me.[MyFKControl] = Me.OpenArgs
End If

Brian
 
B

Brian Bastl

Forgot to ask a question:

Is there a reason you can't simply use a form/subform arrangement? It is a
whole lot cleaner, with no coding.

Brian


Brian Bastl said:
Swagener,

One way is to pass the PK value using the OpenArgs of the OpenForm command,
and assigning it to the appropriate control in the On Load event of the
'Other' form.

***on main form***
'save record
If Me.Dirty Then
Me.Dirty = False
End If

DoCmd.OpenForm "OtherForm" , , , , , , Me.MyPK

*** load event on called form***
If Not IsNull(Me.OpenArgs) Then
Me.[MyFKControl] = Me.OpenArgs
End If

Brian


Swagener said:
Hi ,
I have a main form where new records are added, one of those fields is
a autonumber which is a primary key. The user will fill out all the
fields and open the next form which is bound to a different table but
has a Foreign key of the last table (which will be blank as its a new
record in the main table) , i can't figure out how to copy the id from
the first form and paste it onto the next form in the foreign key field

on openevent.

Thanks,
Riq
 
S

Swagener

Yes i won't be able to do that as there are series of different
attributes that needs to be filled.

*** load event on called form***
If Not IsNull(Me.OpenArgs) Then
Me.[MyFKControl] = Me.OpenArgs
End If

What does .[MyFKControl] stands for ?
 
B

Brian Bastl

It means that you need to replace that with the actual name of the control
in your called form which corresponds to the PK in your main form.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top