Primary Key (1 Viewer)

KirstenII

Registered User.
Local time
Today, 06:54
Joined
Jan 9, 2001
Messages
13
I am still having problems with my primary key.

I am using "Unit Number" as my primary key in my main form. I would like to use a command button on this main form to go to the related record in another form in order to enter and view data. It seems as though I have the link established, however when I try to save records in the second form, it claims that I have a null value in the primary key (Unit Number).

Would this be something that's caused by an incorrect relationship??? How could I correct this (or even find out where the problem is)???

Thanks in advance for any advice or ideas.
 

BarkerD

Registered User.
Local time
Today, 06:54
Joined
Dec 1, 1999
Messages
106
When you are creating the new record on the second form, Access does not know what Unit Number to use. In a sub-form with links established, it uses the value from the main form.

Here is what I would do. On the Command button, send the Unit Number on the form open call.

Dim strOpenArgs as String
strOpenArgs=Me.UnitNumber

Docmd.OpenForm "FormName",,,,,strOpenArgs

On the second form Load Event add.

If Isnull(Me.OpenArgs)= True Then
'Do Nothing
Else
Dim strUnitNumber as String
strUnitNumber=me.OpenArgs.

'You may need to do some conversion if Unit Number is an Integer
If IsNumeric(strUnitNumber)= True then
Me.UnitNumber.DefaultValue=CInt(strUnitNumber)
End If

End If

Duane Barker
 

KirstenII

Registered User.
Local time
Today, 06:54
Joined
Jan 9, 2001
Messages
13
Been away for awhile but finally got a chance to try your advice. It worked well; thanks again for your help!!!
 

Users who are viewing this thread

Top Bottom