473,396 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Prevent duplicate entries in a form in Access 2007

547 512MB
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 4661
MMcCarthy
14,534 Expert Mod 8TB
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 512MB
thx for help
Oct 6 '10 #3
NeoPa
32,556 Expert Mod 16PB
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 512MB
thx for the info
Oct 9 '10 #5

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

Similar topics

17
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...
5
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...
1
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...
1
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 -...
6
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",...
2
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...
4
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...
4
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...
4
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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,...
0
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
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...
0
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...
0
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,...

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.