checking if the same name is in the system?

darksniper

Registered User.
Local time
Today, 06:55
Joined
Sep 4, 2005
Messages
108
I have a form where I enter student names, and it often happends that I enter the same student a couple times, Is there any way to let the user know that there is allready someone in the system with the same name, like a pop up message.:confused:

thx
 
You could use the after update event to run a query to see if the name exists in the table already.
 
I would use the BeforeUpdate event and give the user the opportunity to cancel the event. DCount() is probably the function to use to check for the duplicate. There are other methods available too.
 
is it possible to be more specific, I am not that good with vb nor access,
 
Create a query that selects the student name from your table
In the criteria section of the column (relating to the student name)
type forms![yourformname]![yourstudentfieldname]

on your form in the after update event of the studentnamefield type

Dim nodata as string

nodata = nz(dlookup("[querycolumnname]","[queryname]"),"")

if nodata <> "" then
msgbox "This Student Already Exists",vbinformation,"Duplicate Student"
studentfieldname.setfocus
exit sub
end if
 
Ideally you shouldn't prevent a record from being added if there is already a student with that name. What if you have two students with the same name ?

As a solution you might use a field such a student number, and set it's index to Yes(No Duplicates), so that it will prevent you from entering a student twice with the same student number.
 
the code is giving error at this line

Private Sub Name_AfterUpdate()
Dim nodata As String

nodata = Nz(DLookup("[Name]", "[studentNames]"), "")

If nodata <> "" Then
MsgBox "This Student Already Exists", vbInformation, "Duplicate Student"
name.SetFocus
End If

End Sub

and on "name.SetFocus" is suppose to be Name with big N, but the program allways changes it to smaller.

allso if I dont change the line studentfieldname.setfocus to name.setfocus then the program tell me that the name I am trying to input is allready in the system but it is not.
 

Users who are viewing this thread

Back
Top Bottom