Dlookup

Leesha
BronzeLounger
Posts: 1488
Joined: 05 Feb 2010, 22:25

Dlookup

Post by Leesha »

Hi,
I'm using the following code on the after update event to see if the [store_id} is already in the table. The format of the control is a number set to double. The problem is that the code responds back that the number exists even when it doesn't. I even tried inputting the number into an unbound conrol but that didn't work either.

If Not IsNull(DLookup("Store_ID", "tblStoreDemographics-UniqueID", "Store_ID")) Then
MsgBox "WARNING: This Store ID already exists. Please be sure you wish to duplicate it."
Me.STORE_ID.SetFocus
Exit Sub
End If


Thanks!
Leesha

JohnH
3StarLounger
Posts: 287
Joined: 09 Mar 2010, 23:16
Location: Canberra Australia

Re: Dlookup

Post by JohnH »

Use the Before Update event rather than the After Update.
Then set Cancel = true if you want the new valued to be Cancelled.
Regards

John

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Dlookup

Post by HansV »

DLookup("Store_ID", "tblStoreDemographics-UniqueID", "Store_ID") is not correct - the 3rd argument should be a where-condition. Try changing it to

DLookup("Store_ID", "tblStoreDemographics-UniqueID", "Store_ID=" & Me.Store_ID)

if Store_ID is a number, or to

DLookup("Store_ID", "tblStoreDemographics-UniqueID", "Store_ID=" & Chr(34) & Me.Store_ID & Chr(34))

if it is text.
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1488
Joined: 05 Feb 2010, 22:25

Re: Dlookup

Post by Leesha »

Thanks Hans! The combo of the two responses did the trick.

Leesha