I am trying to make a fancy After Update event in a lookup field that is on a main form.
I am kind of trying to make a template for myself.
Can you review and see my mistake? I tried 2 methods. The 1st method WORKS and retrieves One ID and all the fields needed.
I have a criteria in the underlying query qryCustomerInfo.
Private Sub cboID_AfterUpdate()
'1/18/2015 method 1 works with a criteria in the qry.
'The qry criteria in the ID field is [Forms]![frmCustomer]![cboID]
Me.RecordSource = "qryCustomerInfo"
Me.Refresh
End Sub
HOWEVER, I am next trying a method #2 to avoid having a Criteria in the underlying qry named qryCustomerInfo.
Then i can use qryCustomerInfo for other lookup fields in this main form.
In method #2, I enter an ID number in the lookup field cboID and hit enter. I get an error message of :
"Access cannot find the field 'recordsource' referred to in your expression".
Private Sub cboID_AfterUpdate()
'method 2. ID and cboID are numbers.
On Error GoTo Err_cmdCboID_Click
Dim strSQL As String
Me!RecordSource = "qryCustomerInfo"
strSQL = Me!RecordSource = "Select * From [qryCustomerInfo]" & _
"Where [ID]=[frmCustomer]![cboID]"
'remember to use Order BY for sorting a different issue.
DoCmd.Maximize
Exit_cmdCboID_Click:
Exit Sub
Err_cmdCboID_Click:
MsgBox Err.Description
Resume Exit_cmdCboID_Click
End Sub
thank you.
I am kind of trying to make a template for myself.
Can you review and see my mistake? I tried 2 methods. The 1st method WORKS and retrieves One ID and all the fields needed.
I have a criteria in the underlying query qryCustomerInfo.
Private Sub cboID_AfterUpdate()
'1/18/2015 method 1 works with a criteria in the qry.
'The qry criteria in the ID field is [Forms]![frmCustomer]![cboID]
Me.RecordSource = "qryCustomerInfo"
Me.Refresh
End Sub
HOWEVER, I am next trying a method #2 to avoid having a Criteria in the underlying qry named qryCustomerInfo.
Then i can use qryCustomerInfo for other lookup fields in this main form.
In method #2, I enter an ID number in the lookup field cboID and hit enter. I get an error message of :
"Access cannot find the field 'recordsource' referred to in your expression".
Private Sub cboID_AfterUpdate()
'method 2. ID and cboID are numbers.
On Error GoTo Err_cmdCboID_Click
Dim strSQL As String
Me!RecordSource = "qryCustomerInfo"
strSQL = Me!RecordSource = "Select * From [qryCustomerInfo]" & _
"Where [ID]=[frmCustomer]![cboID]"
'remember to use Order BY for sorting a different issue.
DoCmd.Maximize
Exit_cmdCboID_Click:
Exit Sub
Err_cmdCboID_Click:
MsgBox Err.Description
Resume Exit_cmdCboID_Click
End Sub
thank you.