troubleshooting Question

how can exce vba open an access query then immediately return to vba

Avatar of rberke
rberkeFlag for United States of America asked on
Microsoft Access
8 Comments2 Solutions854 ViewsLast Modified:
The following excel code opens an access query.  but, myQry has criteria:   select * from mytable where cily like  [enter part of city name] & "*"

I have to wait for the input criteria to be entered, before the control is returned to excel.  
Is there any way to prevent that, without changing myQry?  (One way is to use Shell, but I prefer using automation.)


Option Explicit
Dim oApp As Object
Sub openQryx()
    If oApp Is Nothing Then Call openoApp
    oApp.docmd.openquery "myQry"
End Sub

Sub openoApp()
   Dim lPath
    lPath = "S:\.....mdb"

    If oApp Is Nothing Then
        Set oApp = CreateObject("Access.Application")
        oApp.Visible = True
        oApp.OpenCurrentDatabase lPath
    End If
End Sub
ASKER CERTIFIED SOLUTION
Leigh Purvis
Database Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros