Results 1 to 3 of 3

Thread: ADO and Access Validation

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2006
    Posts
    53

    ADO and Access Validation

    Hi,

    I'm using VB to create a front-end for an access database and I've set up some validation in Access but was wondering how to refer to these in my app to save writing my own duplicate error handling routines. For example, the primary key must be unique and when I try and save data that isn't unique, I get a fatal error, but want to turn this into something more user friendly. I suppose basically I'm asking how to customise the error messages (I've tried entering Validation text in Access but this doesn't affect the programme).

    Thanks for any help

  2. #2
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: ADO and Access Validation

    Since you are using Access, just make the primary key field an autonumber field, and don't try to write any values to it in your code. When you create a new record, the autonumber field will increment automatically and will always be unique.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ADO and Access Validation

    Each error will have its own err number. Go through your program and let it error. Jot down the error number and the condition which caused the error. Now, in your program, add error trapping which checks for individual error numbers. Example:
    Code:
    Private Sub Command1_Click()
    On Error GoTo ErrTrap
    'your code goes here
    Exit Sub
    ErrTrap:
    Select Case err.number
         Case 123
            Msgbox "User Friendly message"
        Case 456
            Msgbox "User Friendly message"
        Case 789
            Msgbox "User Friendly message"
    'etc
        Case Else
            Msgbox "An error has occured.  It is " & err.number & " " & err.description
    End Select
    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width