473,769 Members | 8,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preventing Duplicate Records

I have a table (tblStatus) with three fields (CustomerID, StatusType
and StatusDate). I use an unbound form with three text boxes to enter
data into the table when a command button (cmdSave) is clicked.

CustomerID, StatusType are values that are manually entered by the
user; StatusDate is automatically filled with the current date that
the record is saved.

I would like to use code behind the cmdSave button to check the table
for duplicate dates....I only want one record entered per day per
customer.

Hope I have explained my situation...I appreciate any help or
resources you can point me to.

Many thanks in advance - RJ Shrader
Jan 17 '08 #1
9 4149
Have you tried using DCount() of DLookup() before saving?
http://www.mvps.org/access/general/gen0018.htm

rj*******@gmail .com wrote:
>I have a table (tblStatus) with three fields (CustomerID, StatusType
and StatusDate). I use an unbound form with three text boxes to enter
data into the table when a command button (cmdSave) is clicked.

CustomerID, StatusType are values that are manually entered by the
user; StatusDate is automatically filled with the current date that
the record is saved.

I would like to use code behind the cmdSave button to check the table
for duplicate dates....I only want one record entered per day per
customer.

Hope I have explained my situation...I appreciate any help or
resources you can point me to.

Many thanks in advance - RJ Shrader
--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200801/1

Jan 17 '08 #2

<rj*******@gmai l.comwrote in message
news:d1******** *************** ***********@c4g 2000hsg.googleg roups.com...
I have a table (tblStatus) with three fields (CustomerID, StatusType
and StatusDate). I use an unbound form with three text boxes to enter
data into the table when a command button (cmdSave) is clicked.

CustomerID, StatusType are values that are manually entered by the
user; StatusDate is automatically filled with the current date that
the record is saved.

I would like to use code behind the cmdSave button to check the table
for duplicate dates....I only want one record entered per day per
customer.

Hope I have explained my situation...I appreciate any help or
resources you can point me to.

Many thanks in advance - RJ Shrader
Put a unique index on the CustomerID and StatusType fields in the table.
Jan 17 '08 #3
On Jan 16, 9:55*pm, "ruralguy via AccessMonster.c om" <u12102@uwe>
wrote:
Have you tried using DCount() of DLookup() before saving?http://www.mvps.org/access/general/gen0018.htm

rjshra...@gmail .com wrote:
I have a table (tblStatus) with three fields (CustomerID, StatusType
and StatusDate). I use an unbound form with three text boxes to enter
data into the table when a command button (cmdSave) is clicked.
CustomerID, StatusType are values that are manually entered by the
user; StatusDate is automatically filled with the current date that
the record is saved.
I would like to use code behind the cmdSave button to check the table
for duplicate dates....I only want one record entered per day per
customer.
Hope I have explained my situation...I appreciate any help or
resources you can point me to.
Many thanks in advance - RJ Shrader

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.c omhttp://www.accessmonst er.com/Uwe/Forums.aspx/databases-ms-access/2008...- Hide quoted text -

- Show quoted text -
I have played with both and understand how to use DCount to retrieve
the number of occurrences of a record and with DLookup to retrieve a
value. I added a MSGBOX (variable) to display the results so I could
see what was being retrieved or counted....but I do not understand how
to use them to check for the duplicate.
Jan 17 '08 #4
On Jan 17, 8:05*am, "paii, Ron" <n...@no.comwro te:
<rjshra...@gmai l.comwrote in message

news:d1******** *************** ***********@c4g 2000hsg.googleg roups.com...


I have a table (tblStatus) with three fields (CustomerID, StatusType
and StatusDate). I use an unbound form with three text boxes to enter
data into the table when a command button (cmdSave) is clicked.
CustomerID, StatusType are values that are manually entered by the
user; StatusDate is automatically filled with the current date that
the record is saved.
I would like to use code behind the cmdSave button to check the table
for duplicate dates....I only want one record entered per day per
customer.
Hope I have explained my situation...I appreciate any help or
resources you can point me to.
Many thanks in advance - RJ Shrader

Put a unique index on the CustomerID and StatusType fields in the table.- Hide quoted text -

- Show quoted text -
Unique indexes will not work because I may have the same CustomerID
being used on different days. I just want to prohibit duplicate
entries on the date. If I put indexed on the date, then I would only
be able to enter one entry per day...regardles s of CustomerID.
Jan 17 '08 #5
In your SaveCommand button, check for duplicates before saving and don't save
if you find one.

rj*******@gmail .com wrote:
>On Jan 16, 9:55Â*pm, "ruralguy via AccessMonster.c om" <u12102@uwe>
wrote:
>Have you tried using DCount() of DLookup() before saving?http://www.mvps.org/access/general/gen0018.htm
[quoted text clipped - 23 lines]
>>
- Show quoted text -

I have played with both and understand how to use DCount to retrieve
the number of occurrences of a record and with DLookup to retrieve a
value. I added a MSGBOX (variable) to display the results so I could
see what was being retrieved or counted....but I do not understand how
to use them to check for the duplicate.
--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

Jan 17 '08 #6
Please post your DCount() code so we can see it.

rj*******@gmail .com wrote:
>On Jan 16, 9:55Â*pm, "ruralguy via AccessMonster.c om" <u12102@uwe>
wrote:
>Have you tried using DCount() of DLookup() before saving?http://www.mvps.org/access/general/gen0018.htm
[quoted text clipped - 23 lines]
>>
- Show quoted text -

I have played with both and understand how to use DCount to retrieve
the number of occurrences of a record and with DLookup to retrieve a
value. I added a MSGBOX (variable) to display the results so I could
see what was being retrieved or counted....but I do not understand how
to use them to check for the duplicate.
--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200801/1

Jan 17 '08 #7
Excellent! Have fun with the rest of the project.

rj*******@gmail .com wrote:
>On Jan 17, 10:10Â*am, "ruralguy via AccessMonster.c om" <u12102@uwe>
wrote:
>Try:
ScanCount = DCount("StatusD ate", "tblStatus" , "CustomerID Â*= '" &
[quoted text clipped - 40 lines]
>>
- Show quoted text -

That seems to work. Looks like the inclusion of the following code at
the end resolve the problem. I still have so much to learn...I was not
aware that I could have AND other criteria.

Many thanks to you and to all for their suggestions.

AND [YourDateField] =#" & Date() & "#")
--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200801/1

Jan 17 '08 #8

<rj*******@gmai l.comwrote in message
news:e3******** *************** ***********@s13 g2000prd.google groups.com...
On Jan 17, 8:05 am, "paii, Ron" <n...@no.comwro te:
<rjshra...@gmai l.comwrote in message

news:d1******** *************** ***********@c4g 2000hsg.googleg roups.com...


I have a table (tblStatus) with three fields (CustomerID, StatusType
and StatusDate). I use an unbound form with three text boxes to enter
data into the table when a command button (cmdSave) is clicked.
CustomerID, StatusType are values that are manually entered by the
user; StatusDate is automatically filled with the current date that
the record is saved.
I would like to use code behind the cmdSave button to check the table
for duplicate dates....I only want one record entered per day per
customer.
Hope I have explained my situation...I appreciate any help or
resources you can point me to.
Many thanks in advance - RJ Shrader

Put a unique index on the CustomerID and StatusType fields in the table.-
Hide quoted text -
>
- Show quoted text -
Unique indexes will not work because I may have the same CustomerID
being used on different days. I just want to prohibit duplicate
entries on the date. If I put indexed on the date, then I would only
be able to enter one entry per day...regardles s of CustomerID.

You can create a combined index based on both fields and have 1 record per
day for each CustomerID
Jan 17 '08 #9
ruralguy via AccessMonster.c om wrote:
Excellent! Have fun with the rest of the project.

rj*******@gmail .com wrote:
>On Jan 17, 10:10 am, "ruralguy via AccessMonster.c om" <u12102@uwe>
wrote:
>>Try:
ScanCount = DCount("StatusD ate", "tblStatus" , "CustomerID = '" &
[quoted text clipped - 40 lines]
>>- Show quoted text -
That seems to work. Looks like the inclusion of the following code at
the end resolve the problem. I still have so much to learn...I was not
aware that I could have AND other criteria.

Many thanks to you and to all for their suggestions.

AND [YourDateField] =#" & Date() & "#")
You could also use the following psudo code to search duplicates
returned for a dynaset based on appropriate sql code, which would yield
more than one record if a duplicate record is found:

me.RecordSource = "Appropriat e SQL Code here to return a dynaset"
'Determine if more than one record is returned
if me.RecordsetClo ne.RecordCount 1 then
'Do whatever if more than one record is returned
Else
'Do whatever if only one record (or no records) are returned.
End If
Feb 2 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3627
by: Drew | last post by:
I have a permission tracking app that I am working on, and I have made the insert page for it. I am having issues on how to prevent duplicates from getting entered. Currently the interface for the app has a mixture of select boxes, list boxes and checkboxes. The form submits the page to processAIMR.asp and then does the inserting. I am using a loop to insert a new record for each checkbox checked or listbox entry selected. My...
3
2179
by: ColinWard | last post by:
I am using the following code to validate that the person that is being entered into the database does not already exist. However wnem I test it by entering myself as a contact(I first checked that I was indeed NOT in the database), the message still comes up saying that I am in the database. what am I doing wrong? Private Sub txtEmailName_AfterUpdate() On Error GoTo Err_txtEmailName_AfterUpdate >> If DLookup("EmailName", "Contacts",...
5
2954
by: Darrel | last post by:
I have a web form that inserts a record into a DB. This function is called from the button_click subroutine. After the record is inserted, I show/hide some different panels and let the page postback. The problem is that if a person reloads this page after submitting, a new record is inserted into the DB. Short of doing an actual compare query prior to entering the new record, or
1
11788
by: Colin Spalding | last post by:
My problem is that the 'INSERT INTO' query that sends the records to the table is dynamically compiled in VBA and and the target table has a two column primary key. I have made a number of attempts at getting 'WHERE NOT EXISTS' to cure the problem but so far without success and previous postings have resulted in advice to create an 'ignore duplicates' index. This solved the problem in as much as it allowed the SQL to insert the records...
2
3382
by: Allen Anderson | last post by:
Hi, I'm trying to design contact (names and addresses) tables in an Access database. Some of the contacts represent vendors, some are board members of the organization, some are donors, some are neighbors of the organization, some are politicians, etc. Rather than create separate tables for each type of contact, I thought it would be better to have: one table with names/addresses one table with kinds of lists (vendors, board...
1
2005
by: pcnorb | last post by:
I have a form, pulling data from a Products table that has many fields that do lookups to other tables. These are in a one-to-many relationship to a pk in each of said tables. I'd like to be able to compare the data on a BeforeUpdate event to be sure that this data is not duplicated. Here is the structure: Products 8-1 Frames
6
11906
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and clicks again, which created duplicate forcm submission and hence duplicate records. So I am trying to disable the button as soon as it is clicked, and as soon as it's done,
2
2073
by: nethravathy | last post by:
Hi, The following table namely elcbtripselect contains 5147 records.I want to know wether this table contains duplicate records or not. I tried with following query 1)SELECT elcbtripselect.ELCBTRIP_voltsMIN, elcbtripselect.ELCBTRIP_voltsMAX, elcbtripselect.ELCBTrip_is_partwinding, elcbtripselect.ELCBTrip_is_ydelta, elcbtripselect.ELCBTRIP_starter_size, elcbtripselect.ELCBTRIP_UnitFunction, elcbtripselect.ELCBTRIP_strcb_speedi_frame_ty,...
2
4016
by: nomvula | last post by:
hi guys i need some help to duplicate records on my form datasheet: here's the example of my form results: ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual UJ 18-Apr-08 01-Mar-08 Fees: Asset 1 R 31,200.00 R 31,200.00 NMBM 22-Apr-08 23-Mar-08 P-MI (E) 07/2006 3 R 47,485 R 38,849 i have 200 records deplayed in the form i'm using access2007 and i have a command button which is the built in command button to...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3965
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 we have to send another system
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.