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