473,480 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Message Box for a Duplicate Entry

bwesenberg
17 New Member
Hello All

I have a form that my users enter their Audits in. The Primary key is the RECID field.
They enter a policy number and an effective date in this form as well.
What they want to happen is after they enter the policy number tab and enter the effective date if the Policy Number and the Effictive date is a duplicate record they want an warning message. However they want to be able to continue to enter this record.
They just want to be made aware that it is a duplicate.

Can this be done. I know it will be code but if it can be done can you help me out with the code.

Thanks
Sep 15 '08 #1
7 5437
missinglinq
3,532 Recognized Expert Specialist
Is PolicyNumber Numeric or Text?

Linq ;0)>
Sep 15 '08 #2
NeoPa
32,556 Recognized Expert Moderator MVP
It can be done, and we can help with the code.

To know how to pitch this we will need to know whereabouts you are with your understanding and progress.

I will start off by saying that a DLookup() call based on the [Policy Number] and the [Date] will be required.

This will work much better if you can post the meta-data (info about the layout / structure) of the table in the same way as I use in my example. Click on the Reply button and you will have access to all the codes I've used. PK & FK stand for Primary Key & Foreign Key respectively. Never use TABs in this as the layout gets mucked up. Use spaces and all is fine.
Table Name=[tblStudent]
Expand|Select|Wrap|Line Numbers
  1. Field           Type      IndexInfo
  2. StudentID       AutoNumber    PK
  3. Family          String        FK
  4. Name            String
  5. University      String        FK
  6. Mark            Numeric
  7. LastAttendance  Date/Time
Sep 15 '08 #3
ADezii
8,834 Recognized Expert Expert
First, a couple of assumptions:
  1. Your Table name is tblAudits with the following Fields:
    • [PolicyNumber] - {TEXT}
    • [EffectiveDate] - {DATE/TIME}
  2. The Text Fields on your Form for the Policy Number and Effective Date are txtPolicyNumber and txtEffectiveDate respectively.
  3. Policy Number is a Text Field.
  4. Only if both the Policy Number and Effective Date are duplicated does the Message Box appear.
  5. This code should probably be placed in the AfterUpdate() Event of both Fields in order to be 100% effective.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub txtEffectiveDate_AfterUpdate()
    2. Dim strMsg As String
    3.  
    4. strMsg = "A Policy Number of [" & Me![txtPolicyNumber] & "] with an Effective Date of [" & _
    5.          Me![txtEffectiveDate] & "] already exists in the database!"
    6. 'Make sure that both Fields contain values
    7. If Not IsNull(Me![txtPolicyNumber]) And Not IsNull(Me![txtEffectiveDate]) Then
    8.   'See if the Policy Number exists in tblAudits
    9.   If DCount("*", "tblAudits", "[PolicyNumber] = '" & Me![txtPolicyNumber] & "'") > 0 Then
    10.     'See if the Effective Date exists in tblAudits
    11.     If DCount("*", "tblAudits", "[EffectiveDate] = #" & Me![txtEffectiveDate] & "#") > 0 Then
    12.       'A Duplicate based on your definition
    13.       MsgBox strMsg, vbExclamation, "Duplicate Record"
    14.     End If
    15.   End If
    16. End If
    17. End Sub
Sep 15 '08 #4
ADezii
8,834 Recognized Expert Expert
It can be done, and we can help with the code.

To know how to pitch this we will need to know whereabouts you are with your understanding and progress.

I will start off by saying that a DLookup() call based on the [Policy Number] and the [Date] will be required.

This will work much better if you can post the meta-data (info about the layout / structure) of the table in the same way as I use in my example. Click on the Reply button and you will have access to all the codes I've used. PK & FK stand for Primary Key & Foreign Key respectively. Never use TABs in this as the layout gets mucked up. Use spaces and all is fine.
Table Name=[tblStudent]
Expand|Select|Wrap|Line Numbers
  1. Field           Type      IndexInfo
  2. StudentID       AutoNumber    PK
  3. Family          String        FK
  4. Name            String
  5. University      String        FK
  6. Mark            Numeric
  7. LastAttendance  Date/Time
Sorry for stepping on your toes, NeoPa. We both must have been replying at the exact same time.
Sep 15 '08 #5
NeoPa
32,556 Recognized Expert Moderator MVP
Only if it takes you 1/2 an hour to post ADezii :D

You know I'm kidding, and you're not stepping on toes anyway. You have every right to post an answer of course.
Sep 15 '08 #6
NeoPa
32,556 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtEffectiveDate_AfterUpdate()
  2. Dim strMsg As String
  3.  
  4. strMsg = "A Policy Number of [" & Me![txtPolicyNumber] & "] with an Effective Date of [" & _
  5.          Me![txtEffectiveDate] & "] already exists in the database!"
  6. 'Make sure that both Fields contain values
  7. If Not IsNull(Me![txtPolicyNumber]) And Not IsNull(Me![txtEffectiveDate]) Then
  8.   'See if the Policy Number exists in tblAudits
  9.   If DCount("*", "tblAudits", "[PolicyNumber] = '" & Me![txtPolicyNumber] & "'") > 0 Then
  10.     'See if the Effective Date exists in tblAudits
  11.     If DCount("*", "tblAudits", "[EffectiveDate] = #" & Me![txtEffectiveDate] & "#") > 0 Then
  12.       'A Duplicate based on your definition
  13.       MsgBox strMsg, vbExclamation, "Duplicate Record"
  14.     End If
  15.   End If
  16. End If
  17. End Sub
Rather than checking both items individually (which will only tell you when both the date and the policy number have previously been used), you should check for at least one item where BOTH date and policy number match in the same record.
Expand|Select|Wrap|Line Numbers
  1. Dim strWhere As String
  2. ...
  3. strWhere = "([PolicyNumber]='%P') AND ([EffectiveDate]=#%D#)"
  4. strWhere = Replace(strWhere, "%P", Me.txtPolicyNumber)
  5. strWhere = Replace(strWhere, "%D", Format(Me.txtEffectiveDate, "m/d/yyyy"))
  6. If DCount(Expr:="*", Domain:="[tblAudits]", Criteria:=strWhere) > 0 Then
  7. ...
NB. To avoid problems with European dates you should always ensure that dates are inserted into your SQL (including the Criteria clause of a Domain Aggregate function) in m/d/yyyy (or any unambiguous) format.

PS. [Whispers]That'll teach him to butt in on my thread - he he he[/Whispers]
Sep 15 '08 #7
NeoPa
32,556 Recognized Expert Moderator MVP
@Becky, I'm sorry, you've found us in a silly mood. Naturally I blame the others in the thread (Linq didn't actually say anything silly I know but he was certainly THINKING it). You can blame it on our extreme youth :D

PS. We will still do what we can to assist of course. ADezii has already supplied some code to start you off with. Let us know how you make out.
Sep 15 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3086
by: Gary Lundquest | last post by:
I have an application with MS Access 2000 as the front end and MySQL as the back end. All was well until I upgraded the MySQL (Linux) server. The Problem: I insert data into a cumulative table....
1
13993
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every...
8
7807
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
12
3652
by: Jared Carr | last post by:
First I wish I knew how this was caused but here is our problem. Sometime in the recent past we got a duplicate table. Here is the result of a pg_dump with a pg_restore for just that table. ...
4
4361
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file...
8
1966
by: DP | last post by:
hi, i've got a price of code, which checks to see if a film is on rent, or available. but how can i actualyl make the cancel button do somthing? because, the cursor gets stuck on the filmID...
5
3972
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
8
13075
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
5
1436
by: azura | last post by:
hi sir.. i had a problem.... i want to make my page friendly user.... i had change my databse table with unique so that when user reclick the save button will came out warning sign... it work..! but...
4
4095
by: AXESMI59 | last post by:
have a project in which I am entering Serial Numbers and Date codes into a Combo box. Serial numbers are all different. However, they could each have the same Date Code. Each Serial Number has a...
0
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.