Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute parameter query from VBA

Status
Not open for further replies.

eHigh

Programmer
Nov 25, 2002
43
US
The following code executes a parameter query.

Sub Command_Click()
executeQuery "LookUp Query", acEdit
End Sub

After clicking the command button, a user can enter data in the parameter textbox or click cancel. If the user hits cancel without entering data, you get the error #2001, you have canceled a previous operation.

How can I prevent error?
 
You need some error checking!
Change your code so it looks like:

Sub Command_Click()

on Error goto ClickError
'if an error occurs jump to the ClickError line
executeQuery "LookUp Query", acEdit

ClickExit:
'Exit the sub
Exit Sub

ClickError:
'You only get here if there's been an error
Select Case Err
'Check the error code
case 2001
'We know this one, so if it occurs, just ignore it

resume next
case else
'This was an unexpected error, so we need to tell someone about it
msgbox err.number & _
vbcrlf & _
err.Description & _
vbcrlf & _
"Please Report This Error To Your Administrator",vbOkOnly,"Command_Click"
'If you put the name of the procedure in the title of the msgbox, you know where it came from.
goto ClickExit
End Select
End Sub ----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top