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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for a name in the database 1

Status
Not open for further replies.

zahara666

Technical User
Nov 1, 2001
78
CA
am entering a person's last name in a field on a form and after I've finished updating I want to check it to check automatically if there are any duplicates of that last name. If there aren't then there shouldn't be any interruption, if there are then I want it to give me something that says there are and list the names and ask what to do next.

my knowledge on how to program is limited, but i need help urgently on this.. i know there is a find command, but i need it to do this automatically after i enter the person's last name..
help! please!
thanks!
j.
 
In the AfterUpdate function of the lastname field try something like the following...

Code:
Private Sub txtLastName_AfterUpdate()

Dim strCompareName as string
if isnull(Dlookup("[LastName]","tblNames", "[LastName] ='" & me.txtLastName & "'")) then
     strCompareName = "" ' There is no duplicate lastname
else
     strCompareName = Dlookup("[LastName]","tblNames", "[LastName] ='" & me.txtLastName & "'") ' There is a duplicate lastname
end if
if me.txtLastName = strCompareName then 
   msgbox "Duplicate Name Exists."
   '''  Code here to do whatever you want
else
   ''' Code here to move on
end if


End Sub

This is pretty rough code and isn't the cleanest but it'll do what you need to do or at least point you in the right direction.
 
Wow!! it worked!! thanks so much.. i've been working on this stupid thing for days now.. WOW!

Maybe you can help with the other question I have posted??? Regarding querying a table for a form??

Thanks again!
J.
 

Now a bit a of a twist: Say I want it to list the duplicated names after it has found it, doesn't Dlookup only look up one value?

Thanks,
J.
 
build an array and start populating it as soon as you find a duplicate name.

land of milk and Honey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top