Autofill value in subform based on entry in main form

C

Casa

Hello everyone;

I have a main form that links to several associated sub forms. All
information on the main and sub forms relate to one object, whose ID is
entered on the main form. I want this ID to autofill on the subforms. My
code for one of my command buttons (on the main form) is:

***
Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "subfrm_Assays"

stLinkCriteria = "[Hole_ID]=" & "'" & Me![Hole_ID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click
End Sub
***
And the code I have in this sub form is:

***
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me![Hole_ID] = Forms![frm_Collar]![Hole_ID]
End Sub
***

But it's not working the way I want. I want the ID to appear on the subform
when it's first opened. It doesn't show up until I've entered in the data
for one complete record and click to add another new record. What am I doing
wrong?

Thanks,
Casa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top