Hi
I am using Excel 2002 reporting from an Access 2002 database.
I am trying to automate an Excel document so that when data is sent to Access via another data source (patient ADT system) in CSV file then Excel will automatically requery the Access db.
The data has to fill starting from cell A3 to overwrite whatever is currently there. But with the current macro below the data is inserting to the left of the current columns instead.
Also, it's not saving the file as indicated in the macro - it is stopping at "activeworkbook.save".
Sub Import_Access()
Windows("DART_Auto.xls").Activate
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=E:\My Documents\HIMS\HDH\Informatics\ED_PIP\DART_Tests.mdb;DefaultDir=E:\My Documents\HIMS\HDH\Infor" _
), Array( _
"matics\ED_PIP;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;")), _
Destination:=Range("A3"))
.CommandText = Array( _
"SELECT qryDART.AdmDateCalc, qryDART.CountOfChartNo, qryDART.Tri1, qryDART.Tri2, qryDART.Tri3, qryDART.Tri4, qryDART.Tri5" & Chr(13) & "" & Chr(10) & "FROM `E:\My Documents\HIMS\HDH\Informatics\ED_PIP\DART_Tests`.qryDART qryDART" & Chr(13) & "" _
, "" & Chr(10) & "ORDER BY qryDART.AdmDateCalc")
.Name = "Query from MS Access Database_1"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = True
.PreserveFormatting = False
.RefreshOnFileOpen = True
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
ActiveWorkbook.Save
'Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs Filename:="e:\DART.xls"
Application.DisplayAlerts = True
Application.OnTime TimeValue("15:30:00"), "Import_Access"
End With
End Sub
All assistance greatly appreciated. Thanks.
I am using Excel 2002 reporting from an Access 2002 database.
I am trying to automate an Excel document so that when data is sent to Access via another data source (patient ADT system) in CSV file then Excel will automatically requery the Access db.
The data has to fill starting from cell A3 to overwrite whatever is currently there. But with the current macro below the data is inserting to the left of the current columns instead.
Also, it's not saving the file as indicated in the macro - it is stopping at "activeworkbook.save".
Sub Import_Access()
Windows("DART_Auto.xls").Activate
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=E:\My Documents\HIMS\HDH\Informatics\ED_PIP\DART_Tests.mdb;DefaultDir=E:\My Documents\HIMS\HDH\Infor" _
), Array( _
"matics\ED_PIP;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;")), _
Destination:=Range("A3"))
.CommandText = Array( _
"SELECT qryDART.AdmDateCalc, qryDART.CountOfChartNo, qryDART.Tri1, qryDART.Tri2, qryDART.Tri3, qryDART.Tri4, qryDART.Tri5" & Chr(13) & "" & Chr(10) & "FROM `E:\My Documents\HIMS\HDH\Informatics\ED_PIP\DART_Tests`.qryDART qryDART" & Chr(13) & "" _
, "" & Chr(10) & "ORDER BY qryDART.AdmDateCalc")
.Name = "Query from MS Access Database_1"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = True
.PreserveFormatting = False
.RefreshOnFileOpen = True
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
ActiveWorkbook.Save
'Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs Filename:="e:\DART.xls"
Application.DisplayAlerts = True
Application.OnTime TimeValue("15:30:00"), "Import_Access"
End With
End Sub
All assistance greatly appreciated. Thanks.