Hi all,
I have three main forms; Case List, Case Details, and Hearing Details. I can click on a court case in the Case List, which will open that case's Case Details form, and then I can click on New Hearing to add to a new hearing entry through the Hearing Details form. The Hearing Details form is based on a table which has [ID] primary key, and [CaseID] foreign key. The Case Details table's primary key is also [ID].
The problem that I am having is that the user manually has to enter the CaseID foreign key (or select the case) in order to link the new hearing entry to the court case from which he just navigated. I would like to automate this; once you click on New Hearing, the CaseID should be automatically filled in based on the record from which the form was accessed. I found out that this is normally done using OpenArgs.
I have the following set up, but it's currently not working:
Case Details Form
Private Sub cmdHearing_Click()
DoCmd.OpenForm "Hearing Details", , , , acFormAdd, acDialog, Me.Parent![ID]
End Sub
Hearing Details Form
Private Sub Form_BeforeUpdate(Cancel as Integer)
Me![CaseID] = Me.OpenArgs
End Sub
Private Sub Form_Open(Cancel as Integer)
Cancel = IsMissing(Me.OpenArgs) Or IsNull(Me.OpenArgs)
If Cancel Then
MsgBox "No Case Specified."
End If
End Sub
The second part of the code is working (unless you navigate from the Case Details form, the Hearing Details form doesn't open), but clicking the button gives runtime error 2452; invalid reference to the Parent property.
Thanks for helping out!