?
Solved

Access 2010 Duplicate Entry Warning Message

Posted on 2012-08-31
7
Medium Priority
?
719 Views
Last Modified: 2012-08-31
Hi,

I am having a little difficulty warning users when then enter a duplicate entry for FirstName & LastName into a form.

I have used the following code from a sample access database that works fine for checking against FirstName & LastName but I also need to check for duplicate entries of Date Of Birth as well.

'WORKS FINE FOR FIRSTNAME & LASTNAME ONLY
If (DCount("*", "[qryPassengersExtended]", "[Passenger_ID]<>" & Nz([tblHAPassengers.Passenger_ID], 0) & " And [Contact Name] = '" & Replace(Nz([Contact Name]), "'", "''") & "'") > 0) Then
'DOESNT CHECK CORRECTLY FOR DOB
'If (DCount("*", "[qryPassengersExtended]", "[Passenger_ID]<>" & Nz([tblHAPassengers.Passenger_ID], 0) & " And [Contact Name] = '" & Replace(Nz([Contact Name]), "'", "''") & "'") > 0 And [qryPassengersExtended]![DOB] <> Me.DOB) Then
'MsgBox "Poss Dupl"

Dim strMsg As String
Dim iResponse As Integer
        ' Specify the message to display.
       strMsg = "Passenger with the same First Name, Last Name and D.O.B. already exists! Do you want to create this as a new Passenger?" & Chr(10)
       strMsg = strMsg & "Click Yes to Continue."
        ' Display the message box.
       iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Confirm Booking?")
If iResponse = vbNo Then
       Me.Undo
Else

.....save form etc

End If

Any ideas anyone?
0
Comment
Question by:andrewpiconnect
  • 4
  • 3
7 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38353930
Try this...


IF  DCount("*", "[qryPassengersExtended]", "[Passenger_ID]<>" & Nz([tblHAPassengers.Passenger_ID], 0) & " And [Contact Name] = '" & Replace(Nz([Contact Name]), "'", "''") & "' AND [DOB] = #" & Me.DOB & "#") > 0  THEN
0
 

Author Comment

by:andrewpiconnect
ID: 38354258
Sorry, It still doesnt work
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38354277
How specifically?

Error message (which one )?
Incorrect data pulled by the query (what are the incorrect results and what would correct data include )?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:andrewpiconnect
ID: 38354317
No Error Message.

If the first and last names are the same but the DOB is different it still prompts the Msg Box.

If you enter a completely different first and last name and DOB the Msg Box stills shows.

I have used this line of code at the beginning of the If statement and it works fine throughout but it only checks the First and Last Name. I really would prefer to have the DOB checked as well.

Many thanks
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 38354384
That explanation helps...

See how this works:


IF  DCount("*", "[qryPassengersExtended]", "[Passenger_ID]<>" & Nz([tblHAPassengers.Passenger_ID], 0) & " And [Contact Name] = '" & Replace(Nz([Contact Name]), "'", "''") & "' AND Format([DOB],'yyyy-mm-dd') = '" & Format(Me.DOB, "yyyy-mm-dd") & "'" ) > 0  THEN 

Dim strMsg As String
Dim iResponse As Integer
        ' Specify the message to display.
       strMsg = "Passenger with the same First Name, Last Name and D.O.B. already exists! Do you want to create this as a new Passenger?" & Chr(10)
       strMsg = strMsg & "Click Yes to Continue."
        ' Display the message box.
       iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Confirm Booking?")
If iResponse = vbNo Then
       Me.Undo
Else

' ETCETERA ...

Open in new window

0
 

Author Comment

by:andrewpiconnect
ID: 38354487
Excellent....works a treat. Many thanks and have a great weekend
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38354490
Glad to help out!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question