Share via

Error 2501 OpenQuery cancelled

Anonymous
2022-01-07T12:02:41+00:00

I am running an access query from VBA in excel.

**Set appAccess = New Access.Application** 

**With appAccess** 

    **Application.DisplayAlerts = False** 

    **.OpenCurrentDatabase strDatabasePath** 

     **.DoCmd.OpenQuery "qryCapacityFru2"** 

    **.Quit** 

**End With** 

**Set appAccess = Nothing** 

I have just had a new PC and the code now throws a 2501 error at the line

     **.DoCmd.OpenQuery "qryCapacityFru2"** 

The code still works fine on my old PC and other PCs.

Any suggestions please.

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2022-01-07T14:29:04+00:00

    Judith,

    When you open the database on the new PC there migh be the yellow bar with the button “Enable Content”.

    If so, then click this button and close the database.

    After that run your code from within Excel.

    There is a chance the problem is gone.

    Jan

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2022-01-07T18:45:14+00:00

    I have already set access to run all macros so all content is already enabled and no yellow bar. Accessing the macro is fine and other commands in the procedure work just fine too. It opens the database as I can see the lock file engaging on the data, it just doesn't like running the query. Which is strange as the code works on other PCs so it must be something not triggered in the new setup.

    Was this answer helpful?

    0 comments No comments