Solved

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

Posted on 1997-05-15
5
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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