"TC" (27 October 2003) wrote
Say the user types the potentially duplicated value into a textbox.
Use a DLookup() function in the BeforeUpdate event of that textbox....
I tried this (DLookup seems to work on either Tables or Query domains only)
but I could not get it to work. What do I need to do? I am checking an
item (item_code) in a table (tblItem) and want to add it ONLY if it is new.
My code (aircode as I'm not at work!!) was something like:
dim varTxt as Variant
varTxt=DLookup("[item_code]","tblItem")
if varTXT ="" Then
msgbox "Item already stored"
cancel=True
end if
in the BeforeUpdate event - of course!
It didn't work! I checked (via msgbox varTxt) what was 'found' and it
showed the last item on the list (which keeps changing, obviously, as I add
more items!)
What am I doing wrong? Can anyone help as I'd like to validate this BEFORE
the user adds all of the other fields - the database then tells them that
the item already exists, much too late as they have typed all the data by
then, to no avail.
Hope you can understand this and - here's hoping you can help me!
Thanks in advance
Nick