Run-time error 3075? OnLoad OpenForm Porblem?

J

Jay

I have a List Box Subform of Customers [frmContactsAll], whereby, when you
double click and choose a particular customer from the list, the unique
identifier "Customer ID" is used to open a second form
called[frmSelectedCustomerContact].

My OnClick code is: DoCmd.OpenForm "frmSelectedCustomerContact", , ,
"CustomerID =" & Me.List where 'List' is my List Box.

This second form ([frmSelectedCustomerContact]) displays particular customer
details taken from the first form.

Up until this point, this works perfectly.

The problem arises when I introduce an "On Load" event within both
forms. -When the Second form 'loads', I close the first form.
-Conversely, if I want to return to the first form again when sitting in the
second form, I close the second form when the first form re-loads.

After the first form re-loads [and by all accounts takes me back "to the
start" to repeat the original steps], now when I double click and choose a
particular customer from the list once more (in order to open the second
form again), my code DoCmd.OpenForm "frmSelectedCustomerContact", , ,
"CustomerID =" & Me.List doesn't work and I receive the following error.

Run-time error '3075':

Syntax error (missing operator) in query expression 'CustomerID='.

Any help greatly appreciated....Regards, Hason
 
A

Allen Browne

This seems to be a problem with timing.

The message:
Syntax error (missing operator) in query expression 'CustomerID='
suggests that the list box is Nulll at the time when the code runs.
Consequently, the expression:
"CustomerID =" & Me.List
evaluates to just:
CustomerID =
which (naturally enough) doesn't work.

You could avoid the error by coding:
"CustomerID =" & Nz(Me.List, 0)
though it may not behave as you expect if you think the list box should have
a value at this time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top