Passing Value to Primary Key (1 Viewer)

forms_are_nightmares

Registered User.
Local time
Today, 13:24
Joined
Apr 5, 2010
Messages
71
I know I can't assign a value to the primary key, however, can it I pass the value? (might be the same as assigning, I suppose)

Here's the problem:

I have a main form that a user will fill out (the form has tab control with several tabs). Once the user fills out the main form, I would like to enable a button that calls another form and assigns/passes the primary key to the subsequent forms. (I have referential integrity set) But I can't figure out a way to do it without adding a bunch more tabs.

Is there any way to accomplish the above or are tabs the only way to go?

thanks
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:24
Joined
Feb 28, 2001
Messages
27,317
If you don't mind a little text-parsing, then when you open that second form, look into copying the PK into a string in the OpenArgs argument.

Then, in the second form, you can see a property called the OpenArgs (might be singular, I'm never sure until I actually open the properties of the form). If that is blank, your form's OnOpen can do one thing, or if not blank, you can parse it and do something else related to the passed parameter.
 

forms_are_nightmares

Registered User.
Local time
Today, 13:24
Joined
Apr 5, 2010
Messages
71
Thanks. I will give it a try and let you know how I get on.
 

forms_are_nightmares

Registered User.
Local time
Today, 13:24
Joined
Apr 5, 2010
Messages
71
Must be doing something a bit off. I am still getting the "can not assign value" error. Here's what I have:

On the main form, in the onclick command of the button:
DoCmd.OpenForm "frm_construction", acNormal, , , , , Me.Vendor

Then on the second form in the On Open event:
If Not IsNull(Me.OpenArgs) Then
Me.Valuebox.Value = Me.OpenArgs
Me.Requery
End If

Just can't get this to work. Any help is greatly appreciated
 

SOS

Registered Lunatic
Local time
Today, 13:24
Joined
Aug 27, 2008
Messages
3,517
Use the form's ON LOAD event. The recordset hasn't loaded yet until then so you can't assign a value to it.
 

forms_are_nightmares

Registered User.
Local time
Today, 13:24
Joined
Apr 5, 2010
Messages
71
i dropped it in and the form opened but the value wasn't passed. no value was entered. I'll keep playing around with the code. any other ideas are welcomed
 

SOS

Registered Lunatic
Local time
Today, 13:24
Joined
Aug 27, 2008
Messages
3,517
Set a breakpoint and make sure that the OpenArgs is getting what it should in the code to open the form and also in the Load event when you are trying to use it.
 

forms_are_nightmares

Registered User.
Local time
Today, 13:24
Joined
Apr 5, 2010
Messages
71
Found out an error in the code and fixed that but still get the "can't assign value" error on the Load event
 

forms_are_nightmares

Registered User.
Local time
Today, 13:24
Joined
Apr 5, 2010
Messages
71
Been playing around with the code and now I get the error that the changes requested would create duplicate values in the primary key...etc.

Note: I can't have duplicate entries.
 

SOS

Registered Lunatic
Local time
Today, 13:24
Joined
Aug 27, 2008
Messages
3,517
So it would appear that it did enter the data in but you can't see it in the form. Is the form that is being opened have its DataEntry property set to YES? That might cause that problem.
 

forms_are_nightmares

Registered User.
Local time
Today, 13:24
Joined
Apr 5, 2010
Messages
71
Good call. The property was set to YES. I found it and changed it before your reply and that's when I started getting the duplicate value error
 

SOS

Registered Lunatic
Local time
Today, 13:24
Joined
Aug 27, 2008
Messages
3,517
You probably should use a DCount to find out if the item exists first and then if it does don't set the OpenArgs part but pass the criteria to the form.

If it doesn't exist then use what you currently have.
 

Users who are viewing this thread

Top Bottom