i have no idea how to change access error handling, for instance if i
index 2 attribtues to be unique i am not sure on how to inform a user
when they have broken this rule and how to correct it...can anyone
help with this please?
You are quite right that db engine error messages ought to be avoided by
having good error trapping first.
The simplest method is to catch the BeforeUpdate() event like this:
private sub MyNumber_BeforeUPdate(cancel as integer)
' myNumber is the field that is defined as Unique
' PrimaryKey is the field that is defined as the primary key
'
dim varTemp as variant
' see if the value exists already
vartemp = dlookup("primarykey","mytable", _
"MyNumber = " & format(me.MyNumber, "0") )
if isnull(varTemp) then
' no problem, it's a brand new value
Cancel = False
elseif varTemp = me.PrimaryKey
' no problem, it's found the same record as the one
' we are on
Cancel = False
else
' oops: notify the user
msgbox me.Mynumber & " already exists in record: " & varTemp
' don't allow the user to save it
Cancel = True
End if
End sub
Hope that helps
Tim F