473,804 Members | 3,228 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prevent duplicate entries in a form in Access 2007

547 Contributor
Hi
This code worked until i changed the "RaceNo" file to text from number format.
What brackets or code should i change to make it work?
This is to prevent duplicate entries.
thx for helping
Neels

Expand|Select|Wrap|Line Numbers
  1. Private Function IsDuplicateRecord() As Boolean
  2.  
  3.     On Error Resume Next
  4.     Dim PreviousRecordID As Long
  5.     IsDuplicateRecord = False
  6.  
  7.     PreviousRecordID = 0
  8.     PreviousRecordID = DLookup("RacetimingID", "RacetimingT", "RacetimingID<>" & RacetimingID & _
  9.     " AND RaceNo=" & RaceNo & " AND [RaceDate]= #" & RaceDate & "#")
  10.     If PreviousRecordID <> 0 Then
  11.         MsgBox "You have entered this item twice"
  12.         IsDuplicateRecord = True
  13.     End If
  14.  
  15. End Function
  16.  
  17.  
  18. Private Sub Form_BeforeUpdate(Cancel As Integer)
  19.  
  20.     If IsDuplicateRecord Then Cancel = 1
  21.  
  22. End Sub
  23.  
Oct 6 '10 #1
4 4688
MMcCarthy
14,534 Recognized Expert Moderator MVP
RaceNo needs to be enclosed in quotes as it is text. Try this ...

Expand|Select|Wrap|Line Numbers
  1. PreviousRecordID = DLookup("RacetimingID", "RacetimingT", "RacetimingID<>" & RacetimingID & _
  2.     " AND RaceNo='" & RaceNo & "' AND [RaceDate]= #" & RaceDate & "#")
Also I assume RaceNo and RaceDate are variables based on your code. If they are control names and not variables you should add a form object reference such as Me! (e.g.) Me!RaceNo
Oct 6 '10 #2
neelsfer
547 Contributor
thx for help
Oct 6 '10 #3
NeoPa
32,579 Recognized Expert Moderator MVP
For the full info on what to use and where see Quotes (') and Double-Quotes (") - Where and When to use them. It even links to another article that deals with how correctly to handle dates in SQL. Probably the area where most mistakes are made.
Oct 9 '10 #4
neelsfer
547 Contributor
thx for the info
Oct 9 '10 #5

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

Similar topics

17
7674
by: Neil | last post by:
A client of mine likes some of the new bells and whistles in Access 2007, and is thinking about converting our A03 format MDB to an A07 format file. However, while some of the users have A07, many do not, and it's not clear when they would get it. His thought was to use the upcoming Access 2007 runtime to allow the users who are still running Office 2003 to be able to run the database. While I use multiple versions of Access on my...
5
1693
by: Hollywood | last post by:
Good day dear members of the comp.databases.ms-access newsgroup. Please I need your help on the following. I'm the administrator of an Access 2007 database. I would like my enterprise personnel could add entries to one specific table by the use of an interface or form without launching the data base (because the data is confidential). We do not have Windows Share Point. Please how can I do so ?
1
4026
by: blademike | last post by:
Hi guys, I'm new to Access & SQL. Currently using Access 2007. What I have: 1) Table: Employee( empID, empName, email, pwd, ... ) 2) Form: - Record source ( SELECT empName, email, pwd FROM Employee ) 3) 1 combo box. cmbName. Row Source (SELECT Employee.empName FROM Employee; 4) 2 textboxes . txtEmail and txtPwd 5) Button : - Register (no info) and Close form ( Close form button created with button wizard ) Notes: email field has...
1
3046
by: BMF | last post by:
Howdy, I am mainly a MySQL user but I have been playing with Access 07 a little bit recently. I created a database with 3 tables. Table ID --- userID -- AutoNumber UserInfo - userID (linked to ID.userID fname -- text lname -- text age -- number
6
4552
by: teser3 | last post by:
I have my PHP inserting into Oracle 9i. But how do I prevent duplicate record entries? I only have 3 fields in the insert in the action page: CODE <?php $c=OCILogon("scott", "tiger", "orcl"); if ( ! $c ) { echo "Unable to connect: " . var_dump( OCIError() );
2
6697
by: ijyoung | last post by:
Am trying to customise automation in Access 2007/Outlook. Using MS template which works ok. However, I have the form set up as a subform an embedded in the main form Although the form works fine in isolation, it does not display its command button when viewed with main form. I am fairly new to this stuff so clearly have done something stupid. In addition, I want to be able to use the check box so that I don't have to add every entry to...
4
1831
Kitty001
by: Kitty001 | last post by:
Hi Guys I am new to MS Access and using MS Access2007. I have been fooling around with Access trying to solve this problem for weeks but i just cant seem to chack it and I need some help. I have a database based on the machines used for the maintenance of a golf course here in South Africa. I have tables containing the "Groups of Machines", "Machines" and the "Types of Fuel" they use with Prices per Lt. I have created a form thats been...
4
7449
cobra35y
by: cobra35y | last post by:
Good Afternoon, I am new to the world of programming. after reviewing this site for info pertaining to my situation, i have declared a loss and posting for help. maybe i am just overlooking the situation, maybe just need a second set of eyes on this. i am in the military and have designed a unit database that allows for all kinds of tracking and reports generation for training meetings to licensing of soldiers on equipment and other...
4
9750
by: AccessUser123 | last post by:
I am trying to get my Access database to INCLUDE duplicate records. I have a simple database with one table that does not have a primary key and I am using one query to generate a report. The data has a lot of duplicate records that need to be included in my report. Is there a way to include duplicate records so that they will show on my report. All table fields that are indexed are set to "Yes, Duplicates OK" and all fields in the report...
1
1197
by: Rick Aguayo | last post by:
In prior versions of MS Access we used to be able to use the wheel on the mouse to scroll thru records when a form is used. In MS Access 2007 we can not scroll thru the records....Or is there some field or option that needs to be turned on to allow this capability?
0
9588
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
10589
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...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10085
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
9161
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
5527
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...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
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.