DLookup

W

William

I have a table (Countries) that contains 2 fields
(Country, City).

I'd like to utilize the DLookup in conjunction with the
AfterUpdate event.

I found the function below in the Northwind db; however,
it still does not work after updating the naming
convention (tables, fields, etc.).

Right now, when clicking the COUNTRY field, I get the
following error:

"You canceled the previous operation."

Does anyone know what's the missing link?

Regards,
William




Private Sub Country_AfterUpdate()
On Error GoTo Err_Country_AfterUpdate

Dim strFilter As String

strFilter = "Country = " & Me!Country

Me!City = DLookup("City", "Countries", strFilter)

Exit_Country_AfterUpdate:
Exit Sub

Err_Country_AfterUpdate:
MsgBox Err.Description
Resume Exit_Country_AfterUpdate

End Sub
 
K

Ken Snell

Usually I've found that this error occurs with the domain functions (such as
DLookup) when you've specified a field name as an argument that is not found
in the table/query.
 
W

William

Ken:

Thank you for your reply. I verified the field names -
they are identical to those in the table.

Do you have any other pointers that might help me solve
this issue?

William
 
K

Ken Snell

You say that you get this error when you click on the Country control? What
are you doing just before you click into that control? I'm guessing that
this error is not related to the DLookup function in the AfterUpdate event,
as that event does not occur when you click into a control.

Do you have code on the control's OnGotFocus or OnEnter event? Is there code
on the OnLostFocus, OnExit, AfterUpdate events of the control that you are
in before you click into this one? Is there code running on any of this
form's events?

How do you get to this control/form? Are you opening the form? Is there code
running on a form's OnOpen event that cancels its opening? Same for a
report?
 
W

William

Ken:

Thanks so much for your detailed feedback.

I went through all the properties again and I noticed that
some control names were not synchronized.

So, the error was based on my part. Again, thanks for
providing me your help on this. I made me realize that I
have to check multiple things in multiple location...

William
 
K

Ken Snell

Glad you found the answer!

William said:
Ken:

Thanks so much for your detailed feedback.

I went through all the properties again and I noticed that
some control names were not synchronized.

So, the error was based on my part. Again, thanks for
providing me your help on this. I made me realize that I
have to check multiple things in multiple location...

William
 

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