Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 12th, 2007, 10:16 AM
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please Help! getting Runtime error 2001

I am a beginner with access and I am trying to create a basic search. I am getting a “runtime error 2001 you canceled the previous operation” when I click the command button and then cancel the search. I used the code below for the on click event for the command button.

Private Sub Command225_Click()
DoCmd.OpenQuery "Issue_Search", acViewNormal
End Sub


The code I used in the query “Issue_Search” is below.

Like [forms]![searchform].[issue_search] & "*"

Also another question I have is after clicking the search button the pop up search box contains the code from referenced query. Does anyone know how to change the text for this pop up box? I am hoping someone can help me out here? TIA.


 
Old April 13th, 2007, 07:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

The command button looks OK. For the query itself, try

Like "'*" & Forms.Searchform.Form.issue_search & "*'"

Note the use of '* and *' surrounded by quotes; and note the extra .Form.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old April 13th, 2007, 07:50 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Waseem,

Welcome to the world of Access VBA.

The 2001 error always occurs when using DoCmd.OpenQuery and the query being opened is cancelled while running.
The allows DoCmd to feed back the "result" of the query action. This is especially useful when performing update queries and you need to know if the records where in fact updated.

To stop this error feeding up, you need to create an error handler in you CommandButtons's code.
For example:
Code:
Private Sub Command225_Click()
On Error Goto Command225_Click_Error
DoCmd.OpenQuery "Issue_Search", acViewNormal

Command225_Click_Exit:
Exit Sub

Command225_Click_Error:
Select Case Err.Number
    Case 2001 'OpenQuery Cancelled.
    'You can put whatever code you want to run when the query is cancelled here.
    'You could have a message box, or do nothing

    Case Else
        With Err
            .Raise .Number, .Source, .Description
        End With

End Select
End Sub
Regards,
Rob





Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does it show Link error 2001? Jams Visual C++ 2 July 10th, 2007 05:15 AM
Another Runtime 2001 Error jladder Access VBA 5 May 25th, 2007 05:22 PM
Runtime Error 2001 ketAccess Access VBA 2 April 11th, 2007 03:44 AM
Run-time error 2001 kcolli20 Access VBA 1 October 3rd, 2006 07:00 AM
Run-time error 2001 ebburks Access 1 June 8th, 2006 06:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.