linking forms

Mikey F

New member
Local time
Today, 07:22
Joined
Feb 16, 2002
Messages
5
Hello!

This EMPLOYEE/ADDRESS database should be easy (famous last words!)... my problemo....

I have two tables, an EMP_DETAILS (name, dob etc) and an EMP_ADDRESS table. An employee can can more than one address. I have 2 forms to view the two tables.

The EMP_DETAILS table is populated and each record has a primary key (EMP_ID), the EMP_ADDRESS table is not populated.

On the form for the EMP_DETAILS I have a command button to open the form for EMP_ADDRESS (for inputting). I have set this to open the second form on the record relating to the current EMP_ID as displayed on the first form.

However when I click the button, the new form opens with the EMP_ID = "0" thus not automatically relating the new EMP_ADDRESS record with the current EMP_ID.

Am I doing something wrong, as I said this looked easy!!!

If you can help I'd be dead chuffed!

Cheers , Mike
 
You mentioned that your employee addresses table is not populated, therefore, if there is not matching record, the second form opens to a new record.

I think perhaps you are using link criteria in your open form statement when you are probably really wanted what would result from using the OpenArgs.

Try this on your command:

DoCmd.OpenForm "EMP_ADDRESS", , , , acFormAdd, , Me.EMP_ID

On the form EMP_ADDRESS, on the OnLoad event, put:

If Not IsNull (Me.OpenArgs) Then
Me.EMP_ID = OpenArgs
End If


I have a demo if you have trouble.
 
Hey Mike,

On the form for the EMP_DETAILS I have a command button to open the form for EMP_ADDRESS (for inputting). I have set this to open the second form on the record relating to the current EMP_ID as displayed on the first form.

On the second form, the form being called, have you set the default value for the EMP ID? If you haven't then go to EMP ID properties and on the second tab, DATA, go to default value and type in:
=Forms![FirstFormName]![EMP ID]
On a NEW RECORD in the second form when you start entering data, this will set the value of the EMP ID to be the same as the value of EMP ID on the first form. Thus linking the 2 together.

However when I click the button, the new form opens with the EMP_ID = "0" thus not automatically relating the new EMP_ADDRESS record with the current EMP_ID.

I think your getting "0" as a value because when your entering a new record it doesn't know to put the EMP ID value from the first form into EMP ID of the second form.

HTH
Shane
 
cheers folks,

I went with shane's idea and it did the trick!

Thanks so much 8-)

Mikey
 

Users who are viewing this thread

Back
Top Bottom