2 error trapping problems on my form

  • Thread starter Thread starter Richardson
  • Start date Start date
R

Richardson

I have a main form/subform combination in Access 2002. Right now I am
encountering 2 error situations that I need to resolve. In both instances,
I am able to have some code execute, but the default error messages still
appear. I would like the default messages to go away completely.
Error 1
An item is not in the combobox Activity(a 2 column combobox with hidden
number and visible text for column 2), limited to list is set to yes.
When the user types in a value not in the list, the Not in List event
occurs, clears the value, and opens a form to add the item. I have
SetWarning off and also used CancelEvent, but once the new form opens, the
default Access error, "This is not in the list", appears. How do I make
that go away?

Error 2
This one is the one giving me the most problems. The same combobox as in
error one is a number field, so it can't have a zero length or null value.
My users keep entering a value, and then for some reason they highlight the
value and delete it. This generates the error in access that a null value
is not allowed. I have tried every event trigger I can think to use and the
Access error still appears before my code runs. The only place I found I
could put my code is in the OnError for the subform and even though my
message box appears, the Access message still come up. I would like to catch
the error before the default message, clear the value, and delete that
record in the subform.
Here is as far as I have gone in VB (As you can see I am not very proficient
at VB yet, so any help is greatly appreciated)

Private Sub Form_Error(DataErr As Integer, Response AS Integer)
If DataErr = 3162 Then
DoCmd.CancelEvent
DoCmd.SetWarnings (False)
MsgBox ("You have tried to enter a blank value. The record will be
deleted.")
Undo

End If
End Sub

Do you have any suggestions for the code or for the event to trigger the
code?
Thanks in advance,
Lori
 
I would guess that you are not setting the Response parameter.

For the form's error eventhandler try
Private Sub Form_Error(DataErr As Integer, Response AS Integer)
If DataErr = 3162 Then
Response = acDataErrContinue
MsgBox ("You have tried to enter a blank value. The
record will be deleted.")
Undo
End If
End Sub

In the combo's NotInList eventhandler, you should set
Response to acDataErrAdded if you wish to continue with the
new value or acDataErrContinue otherwise.

Hope This Helps
Gerald Stanley MCSD
 
Back
Top