View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Run Existing Access Query From Excel


Hi again Eric,

My apologies for not getting back to you earlier but I had some unforseen
delays after my previous post.

I am assuming that you have already set up these queries in Access.

Sub RunAccessQueries()
'Late binding method

Dim ac As Object
Const acExportDelim = 2 'Required with late binding
Const acNormal = 0 'Required with late binding

Dim strDbFullname As String
Dim strDocName As String

'Edit following line to match the path and name
'of the access database with the queries.
strDbFullname = ThisWorkbook.Path & "\" & "Test.mdb"

On Error Resume Next
'Try GetObject first in case Access is already open
Set ac = GetObject(, "Access.Application")

If Err.Number 0 Then
'Error is returned by GetObject if Access not
'already open so use CreateObject
On Error GoTo 0 'Reset error trapping ASAP
Set ac = CreateObject("Access.Application")
End If

ac.OpenCurrentDatabase strDbFullname

'Following line only really required if Access
'already open and GetObject sets ac. However,
'can remain in code.
ac.DoCmd.SetWarnings False

strDocName = "qryMakeTable"
ac.DoCmd.OpenQuery strDocName, acNormal

strDocName = "qryAppend"
ac.DoCmd.OpenQuery strDocName, acNormal

ac.DoCmd.SetWarnings True

ac.Quit

Set ac = Nothing

End Sub

--
Regards,

OssieMac