Run time error 2001

YNWA

Registered User.
Local time
Today, 22:33
Joined
Jun 2, 2009
Messages
905
Hi, I have a search button, which when clicked pops up a Parameter box to enter a surname, when OK is clicked the box searchs the records and filters to that search criteria. Thats all ok.

However if you click "Cancel" on the box, I get the run time error. And it gives me another box with End or Debug options.

As someone else will be using this form, if they click cancel I would like it to do just that, cancel the parameter box and return to the form as normal.

Is there a way to do this?
 
Offcourse there is but we need to know what code is triggered??

This will need to contain a check for data returned or something.... and/or handle the cancel/no data properly.
 
Offcourse there is but we need to know what code is triggered??

This will need to contain a check for data returned or something.... and/or handle the cancel/no data properly.

Yeah I thought that, forgot to add my code to previous post also :rolleyes:

Here is my search button code...

Code:
Private Sub cmdSearch_Click()
Me.Filter = "[fldSurname] = Me.fldSurname"
Me.FilterOn = True
End Sub
 
Me.Filter = "[fldSurname] = Me.fldSurname" ??
That doesnt make sense....

Me.Filter = "[fldSurname] = " & Me.fldSurname
More likely but then your searching the form for the same name that is visible?? No popup box nothing....

It kindoff makes sense you would get a popup saying "give value for Me.fleSurname", is that right???

Instead of above you will want something like:
Dim x as string
x = inputbox .... (lookup inputbox for details)
if x <> "" then
apply filter
endif

or something simular
 
Here is my DB, the Search button on the frmMain and frmClientSearch.

I want a pop upo to appear for the user to enter a surname, which it currently does. I just dont want the run time error if they click cancel.

Thanks
 

Attachments

Me.Filter = "[fldSurname] = Me.fldSurname" ??
That doesnt make sense....

Me.Filter = "[fldSurname] = " & Me.fldSurname
More likely but then your searching the form for the same name that is visible?? No popup box nothing....

It kindoff makes sense you would get a popup saying "give value for Me.fleSurname", is that right???
So all of the above is true ...

And below is your solution
Instead of above you will want something like:
Dim x as string
x = inputbox .... (lookup inputbox for details)
if x <> "" then
apply filter
endif

or something simular
 
I want a pop upo to appear for the user to enter a surname, which it currently does. I just dont want the run time error if they click cancel.
Thanks

Use an error handler

Code:
Private Sub Whatever()
 
On Error GoTo ErrorHandler
 
'the rest of your code here
 
ErrorHandlerExit:
       Exit Sub
ErrorHandler:
       If Err = 2001 Then
             MsgBox "You have cancelled this operation"
       End If
 
End Sub
 
You know what the error is and that it is non fatal, so why not?

Granted he could write some better code but I would take the easy way...
 
You know what the error is and that it is non fatal, so why not?

Granted he could write some better code but I would take the easy way...

Easy way is THE PROBLEM, to many things get done the Easy / Q&D way!
Spend the bloody 5 minutes to get it right!
 
Easy way is THE PROBLEM, to many things get done the Easy / Q&D way!
Spend the bloody 5 minutes to get it right!

Chill Winston, thanks both for your answers. I will try to correct code but if not will error handle that bad boy.

End of the day, its going to be used by 1 person to make simple search on someones surname, it doesn't need to be coded up to death, plus not all of us are advanced and as understanding of coding as people on here.

Thanks again both of you.
 

Users who are viewing this thread

Back
Top Bottom