Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Carrying over the primary key of Primary form to Secondary form?

Status
Not open for further replies.

Tofias1

MIS
Jun 17, 2002
57
US
If anyone has any advice on how to carry over a Primary Key field to a secondary key field using forms it would be greatly appreciated. For an example, I would like the Primary key of a Tbl within a form to carry over to another form once the cmd button is clicked. Would I need to use VB behind the cmd to carry it over? Thanks.
 
that is the easiest..create a module with the parameter name and it becomes a global ID. then assign it on the main form and when the second (sub) form is opened you can then assign the global variable to the field...

hth
bastien Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Thanks a lot. I will look into how to go about doing that. I have programed w / VB in the past so hopefully it will help.
 
I had a post similar to this a little while ago...see below

create module and insert the line:

public strKeyField as (whatever the fieldtype is ) integer

save the module.

in you main form in the create a function in the OnCurrent for the form (this way it will fire whenever the form moves to another record)

Private Sub_OnCurrent_myForm()

strKeyField = me.SedationRecordID.Value

End Sub

This should take care of it. Hopefully :)



Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Ok, I am going to start it right now. I will let you know if it works. Thanks again.
 
Hey, if you are still out there the code does not generate any errors however, nothing happens. I appreciate your help. If there is anything else you can think of it would be appreciated as well.

Tofias1
 
post some of the code and i can have a look Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Maybe it is all wrong but it reads what I would like it to do in psuedo code as a module.

Public Function strKeyField(ClientNumber As Form_Client) As String

On Error GoTo No_Form_Focus:

If Form_Client = True Then

Forms![Form_ComprehensivePlan]!me.ClientNumber.Value = Forms![Form_Client]!me.ClientNumber.Value

End If

Exit Function

No_Forms_Focus:
Form_Client = False
Exit Function

End Function

Any sugestions would be great...

Again thanks for your help

Tofias1
 
not quite what i had in mind

module
public strKey as Integer

on the main form
Private Sub Kyefield_AfterUpdate()
module1.strKey = me.keyfield.value

End Sub


On the Sub Form
Private Sub Form_Open(Cancel As Integer)
me.keyfield.value=strKey

End Sub

it is very simple

Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
I do this a lot and would propose a different strategy:

You want a child form that's a popup form rather than an embedded subform, correct?

1. Base your child form on a query that brings all the fields from the child table, including the parent fkey.
Add the foreign key from the parent table into the query as well (if a join line doesn't automatically appear then you need to set referential integrity).

2. Put a criterion below the parenttable.foreignkey column thus: forms!parentform!parentkeyfieldname

3. Place a text box on the form that is bound to the child table foreign parent key field. Make the default value for this control the same forms!frmparent!fkey reference. Now set the Visible property to FALSE (actually do this after testing). It will hold the value but not be subject to user change.

4. Make sure that the child form has it's modal property set to true. Why? So that someone can't open it, leave it open, then go back to the parent form and change records.

The global variable approach will work too. Typically programmers shy away from global variables. If the code gets changed, or if the existence and need for the variable are forgotten this form could break easily. The approach here is self-contained.

I'll be glad to clarify this if it doesn't make sense (That is if this is what you're trying to do.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top