Subform OnCurrent Error on Main Form Open

138 views Asked by At

I have the following code on a subform's on current, but it errors on open of the main form:

If IsNull([Forms]![frmMContacts]!ID) Then
    With Forms!frmMContacts!frmMContacts_SubPeopleContacts.Form
        .Enabled = False
    End With
Else
    With Forms!frmMContacts!frmMContacts_SubPeopleContacts.Form
        .Enabled = True
    End With
    If Me.NewRecord Then
        Me.txtCurrRec = "New Contact Role Record"
    Else
        Me.txtCurrRec = CStr(Me.CurrentRecord) & " of " & _
        DCount("ID", "tblContactPeople", "FKClient = " & Me.Parent.CM_CID) & " Contact Roles"
    End If
End If

The point of it is, simply to update a text box in the form's footer, to provide a count of records for the sub form. The issue is that when a user opens the main (parent) form, from the main menu, the main record has no record, and the sub form is still loading. In reality, I'm hiding the detail of the main form, and hence this sub form is hidden. The user has to hit 1 of 2 buttons in the main form header. Either find a record (pop-up form) or start a new one (another pop-up form).

When I try to open this main form, I get the error "run-time error '2465' application-defined or object-defined error".

I'm not sure how to trap this and just either make the sub-form disabled or prevent this on-current code form firing, until the parent has a record.

Thanks for any help!

0

There are 0 answers