Hi all, I currently have the standard code on a command button. The form holding the command button shows customer comments and its record source has both fields - 'CustomerNumber' & 'CommentNumber'.
The form which the button opens has a main form and a subform. The main form has the 'CustomerNumber' field, whilst the subform shows comments for that customer and has the 'CommentNumber' field.
How can I change the code to open the form at the correct 'CustomerNumber' and also the subform at the correct 'CommentNumber'?
I imagine its something like...
stLinkCriteria = "[CustomerNumber]=" & Me![CustomerNumber] & "[CommentNumber]=" & [Forms]![frmCustomerSearchDataEntry]![fsubCustomerComments].Form.CustomerNumber
but I get confused referencing subforms
The form which the button opens has a main form and a subform. The main form has the 'CustomerNumber' field, whilst the subform shows comments for that customer and has the 'CommentNumber' field.
How can I change the code to open the form at the correct 'CustomerNumber' and also the subform at the correct 'CommentNumber'?
Code:
Private Sub btnOpenCustomerForm_Click()
On Error GoTo Err_btnOpenCustomerForm_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmCustomerSearchDataEntry"
stLinkCriteria = "[CustomerNumber]=" & Me![CustomerNumber]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Name
Exit_btnOpenCustomerForm_Click:
Exit Sub
Err_btnOpenCustomerForm_Click:
MsgBox Err.Description
Resume Exit_btnOpenCustomerForm_Click
End Sub
I imagine its something like...
stLinkCriteria = "[CustomerNumber]=" & Me![CustomerNumber] & "[CommentNumber]=" & [Forms]![frmCustomerSearchDataEntry]![fsubCustomerComments].Form.CustomerNumber
but I get confused referencing subforms