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
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.
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