473,379 Members | 1,377 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,379 software developers and data experts.

Prevent Duplicate ID, Then go to the record that has that ID

dee
I can prevent a duplicate ID from being entered, but can't figure out
how to go to the record with that already existing ID. Could someone
help? Thanks in advance.

Private Sub ID_BeforeUpdate(Cancel As Integer)

If Not IsNull(DLookup("ID", "contacts", _
"ID = " & Me!ID)) Then

MsgBox "ID Number Already Exists"
Dim Tid As String
Tid = ID
Me.Undo
Cancel = True

DoCmd.GoToRecord , , acFirst
With Forms!FmLeads.RecordsetClone
.FindFirst "ID = " & Tid 'Me!ID

If Not .NoMatch Then

'Bookmark = .Bookmark
End If

End With

'DoCmd.GoToRecord , , acFirst
'Cancel = True

'Me.Undo
'Cancel = True

End If

On Error GoTo Err_ID_BeforeUpdate
Exit_ID_BeforeUpdate:
Exit Sub

Err_ID_BeforeUpdate:

Resume Exit_ID_BeforeUpdate
End Sub

Feb 6 '07 #1
1 1827
It sounds like you are using a bound text box for this
purpose. If so, the current record is being modified,
surely not something you intended. A search text box really
should be unbound and in a different section from the data
bound controls (the form header is commonly used).

Your code should include an else block in the check for
NoMatch. If a match is not found then go to a new record.
--
Marsh
MVP [MS Access]
dee wrote:
>I can prevent a duplicate ID from being entered, but can't figure out
how to go to the record with that already existing ID. Could someone
help? Thanks in advance.

Private Sub ID_BeforeUpdate(Cancel As Integer)

If Not IsNull(DLookup("ID", "contacts", _
"ID = " & Me!ID)) Then

MsgBox "ID Number Already Exists"
Dim Tid As String
Tid = ID
Me.Undo
Cancel = True

DoCmd.GoToRecord , , acFirst
With Forms!FmLeads.RecordsetClone
.FindFirst "ID = " & Tid 'Me!ID

If Not .NoMatch Then

'Bookmark = .Bookmark
End If

End With

'DoCmd.GoToRecord , , acFirst
'Cancel = True

'Me.Undo
'Cancel = True

End If

On Error GoTo Err_ID_BeforeUpdate
Exit_ID_BeforeUpdate:
Exit Sub

Err_ID_BeforeUpdate:

Resume Exit_ID_BeforeUpdate
End Sub
Feb 6 '07 #2

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

Similar topics

3
by: kjaggi | last post by:
I am trying to either write a trigger or a check constraint to prevent duplicates in my table. There are two columns I need to look at for the duplicates and only one combo value for both columns...
9
by: Catherine Jo Morgan | last post by:
Can I set it up so that a certain combination of fields can't contain the same entries, on another record? e.g. a combination of FirstName/LastName/address? Or FirstName/LastName/phone? Or...
4
by: D. Shane Fowlkes | last post by:
This may be a very simple question but I'm stumped none the less. I have a form where a user provides comments. There's a Grid below this form which displays all comments in the table so far. On...
2
by: eazyone | last post by:
I can prevent a duplicate ID from being entered, but can't figure out how to go to that specific record. I keep getting an error message on: Me.Bookmark = rsc.Bookmark Its not opening and...
4
by: =?Utf-8?B?QXNhZg==?= | last post by:
Hi, How can I prevent from an ASP.NET page to resend all the data again when the user press the Refresh button or F5 on the browser? Thanks in advanced, Asaf
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",...
1
by: chicago1985 | last post by:
I have a unique constraint in my Oracle table for 3 fields. If I enter duplicate info on the table using Oracle client I will get an Ora message error ORA-00001 that tells me it is a duplicate entry...
4
by: jbrumbau | last post by:
Hello, I have been successfully using a database I've created for several months to populate an equipment list for a project we've been working on. However, the form has recently stopped working...
4
by: azura | last post by:
how i want to check if there is duplicate entry in my database?? i insert new record which is the same record that i had inserted before,it successfull insert into the database..i don't want that.....
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.