On error displayes default error code instead of the specifyed one (1 Viewer)

darksniper

Registered User.
Local time
Today, 02:06
Joined
Sep 4, 2005
Messages
108
Hi,

I have added error handling code to my combo box.

Code:
Private Sub searchName_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
On Error GoTo ERR_Handler

Set rs = Me.Recordset.Clone
rs.FindFirst "[sdutentId] = " & Str(Nz(Me![searchName], 0))
Exit Sub
ERR_Handler:
MsgBox "Please empty search box before continuing!"
End Sub


But it doesn't display the message in msgbox, it displayed default ms access
error code. which is "The text you have entered isn't an item in the list."

Any idea why would it do it?
 

ChrisO

Registered User.
Local time
Today, 19:06
Joined
Apr 30, 2003
Messages
3,202
There are a few things wrong with that code so first fix those.

Then see if you have ‘Break on all errors’ set in options.
 

darksniper

Registered User.
Local time
Today, 02:06
Joined
Sep 4, 2005
Messages
108
Hi,

I have set break on all errors. Clicked Debug, compile. It doesn't show me anything wrong. Is there anything I can do to find the error in the code.

Thanks.
 

ChrisO

Registered User.
Local time
Today, 19:06
Joined
Apr 30, 2003
Messages
3,202
To get the error handling working you will need to set Break in class module.
The Str function returns a string where positive numbers have a leading space.
That shouldn’t make a difference unless sdutentId is a text field. If it is a text field you would need to wrap the argument in single or double quotes.
But if it is a text field then you are hardly likely to find a sdutentId with a leading space in it.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:06
Joined
Aug 30, 2003
Messages
36,140
Based on the message, you need code in the Not In List event. I suspect that is firing before the update event, which is why you're getting the default message.
 

ChrisO

Registered User.
Local time
Today, 19:06
Joined
Apr 30, 2003
Messages
3,202
Point taken, Paul. :D
My post written @ 6:52AM, my post ignored @ 7:20AM… :eek:
 

RainLover

VIP From a land downunder
Local time
Today, 19:06
Joined
Jan 5, 2009
Messages
5,041
DarkSnipper

I suspect that you have not normalised your Table structure.

If your primary key is AutoNumber there should never be a Null Value.

So the following is incorrect.

>Str(Nz(Me![searchName], 0))<
 

Users who are viewing this thread

Top Bottom