Solved

How to prevent duplicate data entry in a text box??

Posted on 1997-05-15
5
196 Views
Last Modified: 2012-06-27
Hi I have a simple form for data entry, the MDB file contains 4 fields, and I have a form with 4 text boxes bounded to the MDB file. My question is how do I prevent a duplicate entry on the text box??

I have a simple procedure but it gives me runtime error 3426 ??

' After entering data hit the check_duplicate button to
' check for duplicate entry
Private Sub CheckDuplicateButton_Click()
    strBookmark = ContractData.Recordset.Bookmark
    ' CQuote is the textbox name which bound to the MDB file field [Quote #]
    strCriterion = "[Quote #]= '" & UCase(CQuote) & "'"

    ContractData.Recordset.FindFirst strCriterion
    If ContractData.Recordset.NoMatch Then
        ContractData.Recordset.Bookmark = strBookmark
    Else
        MsgBox ("Duplicate Contract # Entry!!")
    End If
End Sub

If I enter a quote# which previously exist it gives me runtime error 3426??

Any idea from you guys or any better way?? Oh I am using VB4.0.


Thanks
0
Comment
Question by:wyan
  • 3
5 Comments
 
LVL 5

Expert Comment

by:y96andha
ID: 1426324
On what line do you get error 3426?
0
 
LVL 2

Expert Comment

by:vorlon
ID: 1426325
What is error 3426? (Don't have a reference next to me, sorry)
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1426326
Error 3426 is "The action was canceled by an associated object."

You said in your question that you got it when you entered something that already exists.
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1426327
Runtime error 3426 should have something to do with calling the update method without an edit or addnew. Are you sure you haven't made an edit earlier, and then when you move to another record and back, it is lost, and when you try update the error 3426 appears?
0
 

Accepted Solution

by:
mikekr earned 50 total points
ID: 1426328
I don't know what an error 3426 is, but the easiest way to prevent dupilcate data is to set the index property of each field in the table to Yes(No Duplicates)... If your text fields on the form are bound to a data contol, when the data control updates the data in the table, and error will be returned... I can't remember the error number, but I'm sure you'll be able to work it out. You can then trap the error at run time, and use code to deal with the error.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now