G
Grahammer
I'm creating some data entry forms for an MS Access database.
Many of my forms have a child form to create records that are related to the
parent form. When I add new records using the child form I need to apply the
key from the data on the parent form to link them. I currently click a
button on my parent form which opens my child form filtered on matches to
the parent... My child form is bound to an SQL query that includes the
parents key. This works well, EXCEPT when there are no matching child
records... then there are no fields that match and I never get the parents
key. Adding a new record to the child fails since the relationship is not
valid. The code below is what I use.
**Parent Form**
Private Sub cmdServiceArea_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "ServiceAreas"
stLinkCriteria = "[BranchKeyLink] = " & Me.[BranchKey]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , vbModal
End Sub
**Child Form**
Private Sub Form_Activate()
txtBranchDesc = BranchDesc
txtBranchKey = BranchKey
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
BranchKeyLink = txtBranchKey
End Sub
What I would like to do is pass the key from the parent form to the child
form, but I don't see how...
I can't put the value onto a hiddle field of the child form, since it hasn't
been shown yet and isn't loaded. The form is modal, so I can't apply the key
after I show the form.
How can I pass the parent's key to the child form so it will be applied to
all the new records?
Many of my forms have a child form to create records that are related to the
parent form. When I add new records using the child form I need to apply the
key from the data on the parent form to link them. I currently click a
button on my parent form which opens my child form filtered on matches to
the parent... My child form is bound to an SQL query that includes the
parents key. This works well, EXCEPT when there are no matching child
records... then there are no fields that match and I never get the parents
key. Adding a new record to the child fails since the relationship is not
valid. The code below is what I use.
**Parent Form**
Private Sub cmdServiceArea_Click()
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "ServiceAreas"
stLinkCriteria = "[BranchKeyLink] = " & Me.[BranchKey]
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , vbModal
End Sub
**Child Form**
Private Sub Form_Activate()
txtBranchDesc = BranchDesc
txtBranchKey = BranchKey
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
BranchKeyLink = txtBranchKey
End Sub
What I would like to do is pass the key from the parent form to the child
form, but I don't see how...
I can't put the value onto a hiddle field of the child form, since it hasn't
been shown yet and isn't loaded. The form is modal, so I can't apply the key
after I show the form.
How can I pass the parent's key to the child form so it will be applied to
all the new records?