On error displayes default error code instead of the specifyed one

darksniper

Registered User.
Local time
Today, 10:45
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?
 
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.
 
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.
 
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.
 
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.
 
Point taken, Paul. :D
My post written @ 6:52AM, my post ignored @ 7:20AM… :o
 
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

Back
Top Bottom