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

Check for Duplicate entries

Status
Not open for further replies.

stavro

Technical User
Oct 16, 2008
4
GB
rivate Function NameOK() As Boolean
Dim NameCount As Integer
NameOK = True

If Surname & "" = "" Or Forename & "" = "" Then Exit Function
If Surname = Surname.OldValue And Forename = Forename.OldValue Then Exit Function

NameCount = DCount("Surname", "mytab", "Surname = """ & Surname & """ AND Forename = """ & Forename & """")

If NameCount = 1 Then
MsgBox "A PLAYER with this NAME & DOB already exists." & vbLf & vbLf & _
"PLEASE CHECK.", vbCritical, "PLAYERS Name"
NameOK = False

End If

End Function

Private Sub Forename_Exit(Cancel As Integer)

If Not NameOK Then
Cancel = True
End If
End Sub
I could someone check my poor vb and see where I have gone wrong. My database is for registered football players and with over 5000 players i need to check that players have not signed for two clubs hope you can help I will be using surname and DOB in the final version
 
doing nothing at presant have checked through but does not work
 
First, try adding an ELSE in your code to see what you're getting.
Code:
If NameCount = 1 Then
    MsgBox "A PLAYER with this NAME & DOB already exists." & vbLf & vbLf & _
        "PLEASE CHECK.", vbCritical, "PLAYERS Name"
    NameOK = False
Else
    MsgBox NameCount, vbOKOnly, "Name Count"
End If


Randy
 
orry nothing happening when entering data into test database still no msgbox appears
 

If no message box appears you must have 1 of 2 problems.

1. You are exiting the function early, based on the criteria set in your first two IF statements.

2. Your NameOK function is not in the same module. Try making it a Public function.


Randy
 
Why not use the wizard to create a duplication query?


Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top