Solved

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

Posted on 1997-05-15
5
199 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

791 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