Hi,
The following code is being run from the AfterUpdate event of a combo box on the subform "frmInvoice". It is intended to first, move the master form "frmCustomer" to the correct Record based on "CustID", then return focus to the subform and then move it to the required Record, based on InvoiceNum. The first half of the code works a treat and does indeed set the Record in the master form to the required "CustID". However when the focus returns to the subform (from which the code is being executed) the code runs but doesn't seem to have any effect, and no errors are generated.
The problem lies in the second DoCmd.FindRecord command (in Red), this is intended to set the subform record to match the InvoiceNum field, stored in variable lngInvNum. The FindRecord command appears to execute, but has no effect.
The record in the subform does change however, but only because the Record in the Master form "frmCustomer" has changed. Because of the way in which the two tables are linked (One to Many) the subform updates automatically to match the first linked Record for the current Record in the Master form (there may be several or more records in the subform table linked to the current Record in Master form). My second DoCmd.FindRecord command is intended to display the precise record chosen by the user in the combo box, but this line of code is simply being ignored, for some reason I cannot fathom.
Private Sub cmbInvNo_AfterUpdate()
Dim lngInvNo As Long
Dim lngCustNo As Long
On Error Resume Next
'obtain search criteria "CustID" & "InvoiceNum"
lngInvNo = Me.cmbInvNo
lngCustNo = DLookup("CustID", "tblInvoice", "[BookingID] = " & lngInvNo)
'set frmCustomer to required 'CustID' record
Parent.txtCustID.SetFocus
DoCmd.FindRecord lngCustNo, acEntire, False, acSearchAll, False, acCurrent, True
'All the above code seems to work well.
'Return focus to subform "frmInvoice" and set to required Record for lngInvNo
Me.txtInvoiceNum.SetFocus
DoCmd.FindRecord lngInvNo, acEntire, False, acSearchAll, False, acCurrent, True
'it is this line of code, above, that is being ignored - executes without error, but has no effect.
'check there has been no error
If Err <> 0 Then
MsgBox "Error has ocurred, Err No : " & Err & ", " & Err.Description, vbCritical, "Error"
End If
On Error GoTo 0
End Sub
I've racked my brains to try and understand why that second DoCmd.FindRecord line (in Red) is having no effect, and refusing to change the Record based on the lngInvNum value. Prof.