urgent linked form help required

GS1

Registered User.
Local time
Today, 22:33
Joined
Jul 3, 2002
Messages
30
Hi

I've got 2 forms set up, in such a way as a user can click on a button on the first form, and it opens the second form showing data related to the first form.

This works ok. When a user tries to add in an extra record in the second form, there is a primary key violation error because the new record on the 2nd form does not automatically fill in the primary key value.

The code in the button that launches the second form is as follows

***************************
Private Sub Pcuttings_Click()

On Error GoTo Err_Pcuttings_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Press Cutting details Subform"

stLinkCriteria = "[Activity ID]=" & Me![Record Number]
DoCmd.OpenForm

Exit_Pcuttings_Click:
Exit Sub

Err_Pcuttings_Click:
MsgBox Err.Description
Resume Exit_Pcuttings_Click

End Sub

****************************

Can anyone tell me how to automatically set the primary key field for any new records added in the second form to relate to the primary key value on the record that the 2nd form was launched from.

I desperately need to fix this before tomorrow morning, so any ideas are most appreciated!

G
 
clarification

I think that the problem is that the second form needs to act like a subform. I don't want it to ever appear on the first form though, as the subform contains a lot of data.

Can I somehow set up the second form to act as a popup form when the button on the first form is pressed?

G
 
You can set the value of the primary key in the BeforeInsert event.

Me.[Activity Id] = Forms!yourotherForm![Record ID]
 
Thanks

Thanks for that - sometimes the answer is hidden in plain sight.

:)
 
complications

Thanks Pat for your help. Unfortunately , I have run into further complications when trying to apply this code to a seperate form.

I have three forms which all need to launch the same subform. is there any way that I can have some code on the subform that reads like:

Me.[Activity Id] = Forms!Form this one was launched from![Record ID]

Can i declare a global variable somehow and set it to the record ID of the record on the form where I am launching the second form from? I'm sure it is possible, but I can't seem to get it right...

Thanks again

G
 
Cracked it

OK - after some poking around I think I've cracked it - for anyone who may be interested, here's what I did:

1. Made a new module and made a Public variable called Referrer_ID

2. Changed the code on the button that launches the second form to include the line:

Referrer_ID = Me![Record Number]

3. Added a 'Before Insert' Event to the second form, with the following code:

Me![Activity_ID] = Referrer_ID

G
 

Users who are viewing this thread

Back
Top Bottom