Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Posts
    13

    Unanswered: error trapping a duplicate value in VB

    I'm having a bit of trouble with a database I'm creating.

    I have a form in access that adds a range of vouchers to the database. The user enters the start number in txtstart, the end number in txtend and the database adds a record for every number between these two numbers.

    However, I want some error trapping in there so if the user trys entering data that will create a duplicate value in the database they will get a message box appearing informing them.

    However, i'm not sure what code I would need in my vba to do this.

    if they enter values that will create duplicates then an error message does appear but this is the standard microsoft one and if I was to add 100 records, then the same message would appear 100 times.

    The coding I have at the min is below:

    start = txtstart
    voucherend = txtend
    vouchervalue = txtvalue

    Do While start <= voucherend
    VoucherNo = start
    Value = vouchervalue
    cmdAddNewRecord_Click
    cmdSaveNewRecord_Click

    start = start + 1
    Loop

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You do not need any special verification code: all you need to do is to create a unique index on the column containing the values that cannot be duplicated. Then, a simple error trapping mechanism would do the job in your application.
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •