dbTalk Databases Forums  

Copy primary key from subform to foreign key in form

comp.databases.ms-access comp.databases.ms-access


Discuss Copy primary key from subform to foreign key in form in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
grim
 
Posts: n/a

Default Copy primary key from subform to foreign key in form - 01-23-2009 , 03:23 AM






Hello

I have a problem. I have two tables one tCustomer , second tOrder.

tCustomer :
IDCustomer

tOrder :
IDOrder
FKCustomer

IDCustomer and FKCustomer are related. In parent form where user input
data of order, he can add new customer. Then, the new subform with
data entry set to 'yes' is activated. He add new record and close
subform. What I must to do, if I want this new customer lto be linked
to record in tOrder that user edit before.

Is there any simple solution for that ?

Reply With Quote
  #2  
Old   
troy23
 
Posts: n/a

Default Re: Copy primary key from subform to foreign key in form - 01-23-2009 , 03:58 AM






On 23 Jan, 09:23, grim <grim... (AT) gazeta (DOT) pl> wrote:
Quote:
Hello

I have a problem. I have two tables one tCustomer , second tOrder.

Right click on the subform and select properties

Make sure the link master and link child properties are set to your
linking ID's from the table. Link master will contain your primary key
and link child your foreign key.


For FREE Access ebook and videos click here
http://access-databases.com/ebook




Quote:
tCustomer :
IDCustomer

tOrder :
IDOrder
FKCustomer

IDCustomer and FKCustomer are related. In parent form where user input
data of order, he can add new customer. Then, the new subform with
data entry set to 'yes' is activated. He add new record and close
subform. What I must to do, if I want this new customer lto be linked
to record in tOrder that user edit before.

Is there any simple solution for that *?


Reply With Quote
  #3  
Old   
grim
 
Posts: n/a

Default Re: Copy primary key from subform to foreign key in form - 01-23-2009 , 04:57 AM



On 23 Sty, 10:58, troy23 <barnettp... (AT) gmail (DOT) com> wrote:
Quote:
On 23 Jan, 09:23, grim <grim... (AT) gazeta (DOT) pl> wrote:> Hello

I have a problem. I have two tables one tCustomer , second tOrder.

Right click on the subform and select properties

Make sure the link master and link child properties are set to your
linking ID's from the table. Link master will contain your primary key
and link child your foreign key.

For FREE Access ebook and videos click herehttp://access-databases.com/ebook

thanks for the fast reply, but i was mistake. I dont have subform, i
open new form and add new record and i want to return to my early
edited form with the record set on that new data.


Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: Copy primary key from subform to foreign key in form - 01-23-2009 , 09:05 AM



grim wrote:
Quote:
Hello

I have a problem. I have two tables one tCustomer , second tOrder.

tCustomer :
IDCustomer

tOrder :
IDOrder
FKCustomer

IDCustomer and FKCustomer are related. In parent form where user input
data of order, he can add new customer. Then, the new subform with
data entry set to 'yes' is activated. He add new record and close
subform. What I must to do, if I want this new customer lto be linked
to record in tOrder that user edit before.

Is there any simple solution for that ?
Let's say you have a button to open the customer form. You could check
if the mainform is a new record. Ex:
If me.newrecord then
...
Endif

You may want to save the main record first before calling the customer
Me.Dirty = False

You might need to requery the customer field. Perhaps customer field is
a combo box called Cust Ex:
Forms!OrderFormName!Cust.Requery


Reply With Quote
  #5  
Old   
robert.waters
 
Posts: n/a

Default Re: Copy primary key from subform to foreign key in form - 01-24-2009 , 01:05 AM



On Jan 23, 5:57*am, grim <grim... (AT) gazeta (DOT) pl> wrote:
Quote:
On 23 Sty, 10:58, troy23 <barnettp... (AT) gmail (DOT) com> wrote:

On 23 Jan, 09:23, grim <grim... (AT) gazeta (DOT) pl> wrote:> Hello

I have a problem. I have two tables one tCustomer , second tOrder.

Right click on the subform and select properties

Make sure the link master and link child properties are set to your
linking ID's from the table. Link master will contain your primary key
and link child your foreign key.

For FREE Access ebook and videos click herehttp://access-databases.com/ebook

thanks for the fast reply, but i was mistake. I dont have subform, i
open new form and add new record and i want to return to my early
edited form with the record set on that new data.
In the new form's Unload event, you could update the "parent" form in
a number of ways:
1) Invoke DoCmd.OpenForm on the parent form, and pass the new record's
ID in parameter 4 (where condition). This will cause the parent form
to requery, and filter by the new ID (so that your new record is
displayed). Ex):
Docmd.OpenForm "parentFormName",,, "id=" & Me.id
(or if you prefer using named parameters, DoCmd.OpenForm
"parentFormName", WhereCondition:="id=" & Me.id)
2) Filter the parent form by the new ID, Ex):
Form("parentformname").Filter ="id=" & Me.id
Form("parentformname").FilterOn = True
3) Alter the parent form's recordsource directly. Ex):
Form("parentformname").RecordSource="SELECT * FROM table WHERE ID=" &
Me.id

Note that item 1) can be used regardless of whether or not the parent
form is open; however, items 2) and 3) require that the parent form be
available as part of the Forms collection, and thus already open.
Make sure that you use proper error handling, because if you try to
access a member of the Forms collection that does not exist, an error
is thrown.

On a related note, if the control on the parent form that you would
like to update is unbound, and you know it's name, you can simply give
it the focus and set it's value from anywhere (including the new
form). Ex):
Forms("parentformname").Text3.SetFocus
Forms("parentformname").Text3.text="whatever"



HTH
-Robert Waters


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.