Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLookup not working

Status
Not open for further replies.

lastout

Programmer
Apr 12, 2002
84
US
I have a Dlookup in a sub that isn?t working. The sub?s purpose is to add a new value to a list in a combobox. When the user enters a new value, a data entry form pops up and they can add the new value plus some other fields pertaining to the new record. The user then clicks the save button in the popup form, and then the close button. At that point an error message comes up saying ?You have cancelled the previous operation.? When I hit the debug button, the Dlookup line of code is highlighted:

Result = DLookup("[Agent]", "tblAgent", "[Agent] = " & NewData)

Does anyone know what is wrong with the line (I'm working with Access 2002)?

Thanks in advance!
 
Several immediate issues I see is to make sure the variable "Result" is Dimmed to the same datatype as that as "Agent".

Then, if the variable "NewData" is of string type, it needs to have quotes, such as this:

Result = DLookup("[Agent]", "tblAgent", "[Agent] = '" & NewData & "'")

Good Luck! Roy
aka BanditWk
Las Vegas, NV
roy@cccamerica.org
RLMBandit@aol.com (private)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top