By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,145 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,145 IT Pros & Developers. It's quick & easy.

Can't Trap combo box error when null entered

P: n/a
When a user clears a value from a combo box (by pressing the delete key),
the following message appears:

"You tried to assign the null value to a variable that is not a variant data
type".

The problem is that I can't trap the error in the Before Update event. The
error is generated before it gets there. Furthermore, I am not trying to
assign the value to any 'variable' (at least not till the AfterUpdate event)

The combo box is set to 'Limit to List', and has no default value.
Control Source is a Long Integer with a default value of '0'.

Can anyone tell me how to interecept this error message?

(Using Access 2002 on Win XP Pro.)

--
Bob Darlington
Brisbane
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Open the table where the field resides, and check if its Required property
is Yes.
If so, it is an engine-level error, so trap it in the Error event of the
Form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:42**********************@news.optusnet.com.au ...
When a user clears a value from a combo box (by pressing the delete key),
the following message appears:

"You tried to assign the null value to a variable that is not a variant
data type".

The problem is that I can't trap the error in the Before Update event. The
error is generated before it gets there. Furthermore, I am not trying to
assign the value to any 'variable' (at least not till the AfterUpdate
event)

The combo box is set to 'Limit to List', and has no default value.
Control Source is a Long Integer with a default value of '0'.

Can anyone tell me how to interecept this error message?

(Using Access 2002 on Win XP Pro.)

--
Bob Darlington
Brisbane

Nov 13 '05 #2

P: n/a
Thanks Allen,
The 'Required' property was 'No', but your solution worked anyway using:

Dim strControl As String

strControl = Screen.ActiveControl.Name

If DataErr = 3162 Then
If MsgBox("You must enter a value for this field. It cannot be left
blank." _
& vbCrLf & "Press OK to continue or Cancel to abort.", 1) =
2 Then
Me.Undo
Else
Me(strControl).Undo
End If
Response = acDataErrContinue
End If

I had always thought that I could trap null values in a control's
BeforeUpdate event.
But the BeforeUpdate sub isn't even addressed before the Form_Error decided
to involve itself.
Is this because it is a combo box?

--
Bob Darlington
Brisbane
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:42***********************@per-qv1-newsreader-01.iinet.net.au...
Open the table where the field resides, and check if its Required property
is Yes.
If so, it is an engine-level error, so trap it in the Error event of the
Form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:42**********************@news.optusnet.com.au ...
When a user clears a value from a combo box (by pressing the delete key),
the following message appears:

"You tried to assign the null value to a variable that is not a variant
data type".

The problem is that I can't trap the error in the Before Update event.
The error is generated before it gets there. Furthermore, I am not trying
to assign the value to any 'variable' (at least not till the AfterUpdate
event)

The combo box is set to 'Limit to List', and has no default value.
Control Source is a Long Integer with a default value of '0'.

Can anyone tell me how to interecept this error message?

(Using Access 2002 on Win XP Pro.)

--
Bob Darlington
Brisbane


Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.