I have a form containing orders which are submitted via email. The purpose of this form is to collect the orders emailed in and validate them then import the correct ones into the "real" tables. So the data this form is bound to is an "import orders" table.
Important: Sometimes I need to create a customer record for this order. Sometimes the customer already exists, so I don't need to create them, just import a new order for them.
To help decide if this is an existing customer, I created a subform by dragging the Customers table onto my form in design mode. The subform is automatically named "Customers subform". I deliberately leave the link fields blank so the subform won't be filtered down, but always keep a full list of customers.
I have code in the subform (a public sub) which causes it to scroll to the proper area when called. The code never gets executed, because I'm getting an error trying to access the subform at all. Here is my main form code:
Code:
Private Sub Form_Current()
Dim frm As Form
On Error Resume Next
Set frm = Me.Controls("Customers subform").Form
If Err.Number = 0 Then
frm.LocateCustomer LastName, FirstName
If Err <> 0 Then
Debug.Print Err, Error
Stop
End If
End If
Set frm = Nothing
End Sub
First time I run this code (after opening the form the Form_Current event is fired), I get this error:
Code:
Error 2455: You entered an expression that has an invalid reference to the property Form/Report.
This is expected, as the subform may have not yet been loaded. This is why I put the On Error Resume Next statement in the code.
Subsequent times invoking the code by moving to a new record causes
Code:
Error -2146500594: Automation error
The error is encountered during the statement
Code:
Set frm = Me.Controls("Customers subform").Form
This code works properly in other databases, so I'm at a loss as to what is happening here. Any ideas? Thanks...