View Full Version : Primary Key


KirstenII
01-17-2001, 01:53 PM
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
01-18-2001, 06:40 AM
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
01-23-2001, 06:25 AM
Been away for awhile but finally got a chance to try your advice. It worked well; thanks again for your help!!!