Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Apr 2004
    Jacksonville, Florida, USA
    Thanked 0 Times in 0 Posts

    Opening vba query in another Access db

    I do way more VBA in Excel than Access, but this time I need to open a query in another db from my db. I'm basically using the same code to run the other db that the other db uses, with a modified Set db=OpenDatabase("path"). However, I'm having trouble with the password on the other db. The code in the other db to run the password is

    DoCmd.OpenQuery "Logon_q"
    DoCmd.Close acQuery, "Logon_q"

    This gives a "can't find the object 'Login_q' error in my db. How do I open and close this query from my db?

  2. #2
    3 Star Lounger HiTechCoach's Avatar
    Join Date
    Sep 2011
    Oklahoma City, OK
    Thanked 37 Times in 36 Posts
    Docmd uses the currently opened database.

    When use open another database that is assigned to the variable db then you must use commands that reference the db variable.

    Is the query a select or action query?

    If an action query then you can use:

    db.Execute "Logon_q", dbFailOnError
    Boyd Trimmell aka HiTechCoach
    Microsoft MVP - Access Expert

    Last edited by HiTechCoach; 2011-09-07 at 12:45.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts