Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Apr 2004
    Location
    Jacksonville, Florida, USA
    Posts
    117
    Thanks
    0
    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. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    2 Star Lounger HiTechCoach's Avatar
    Join Date
    Sep 2011
    Location
    Oklahoma City, OK
    Posts
    162
    Thanks
    0
    Thanked 24 Times in 24 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:

    Code:
    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
  •