?
Solved

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

Posted on 1997-05-15
5
Medium Priority
?
202 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 100 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 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