How to close access database that was opened with Shell?

We have an Excel application that gets data from MS Access.

6 of our computers do not have access installed, so those computers use the access Run Time minimum (version is art2kmin) along with the Shell function.

It has been working well for several years but there is one annoying problem.  Once the database gets open it stays open.  How can I close the database when access is done with it.  

I tried SendMessage(, wm_close)   but that did not work.

I also don't want to kill all Access Tasks because the user might have other databases opened at the same time.
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_CLOSE = &H10
Private lNotepadhWnd As Long


Sub test()
    Dim dummy2 As Long
    Dim db As Object
    
' very small program for sql
    Path = "S:\XYZ program files\Back End Billing.mdb"
    pathArt2k = Replace("C:\Program Files\Microsoft Office\ART\Office\msaccess.exe `S:\XYZ program files\Back End Billing.mdb`", "`", Chr(34))
        On Error Resume Next
    Set db = CreateObject(Path)
    If db Is Nothing Then

        Err.Clear
        dummy2 = Shell(pathArt2k, vbMaximizedFocus)
        If dummy2 = 0 Then dummy2 = Shell(pathArt2kB, vbMaximizedFocus)
        If dummy2 = 0 Then
            MsgBox "Could not open Assess Database"
        Else
            Set db = GetObject(Path)
        End If
    End If

sqlPre = "select * from [out] where apben = 222229 "
Set rsoutpre = db.currentdb.OpenRecordset(sqlPre)
MsgBox rsoutpre.RecordCount
Set rsoutpre = Nothing
db.currentdb.Close

Set db = Nothing


If dummy2 > 0 Then Call SendMessage(dummy2, WM_CLOSE, 0, 0)
End Sub

Open in new window

LVL 5
rberkeConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Eric ShermanAccountant/DeveloperCommented:
Will Application.Quit or DoCmd.Quit work in the runtime version???


ET
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rberkeConsultantAuthor Commented:
You made it easy for me.  Changed the last code as follows.  Thanks

' MsgBox rsoutpre.RecordCount
Set rsoutpre = Nothing

db.Application.Quit
Set db = Nothing


End Sub
0
Eric ShermanAccountant/DeveloperCommented:
Glad I could help.

ET
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.