I am trying to write some VBA code that pulls an Acess query I have already designed in Access through the Query function of Excel. I have successfully written one that does this but need some help in kaing one of the words a variable. You see, I have multiple queries and would like my macro to know run through them using a string variable that I give it. When I run the following code, I get this error: "General ODBC error", and the debugger highlights the very last line of the code below ".Refresh BackgroundQuery:=False"
PLEASE HELP! Thanks!
Sub Export()
'
Dim Condition As String
Condition = Sheets("Sheet4").Range("G1").Value
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=G:\BALARF\MIPPA 2010\Claims Analysis\2007\hcc.mdb;DefaultDir=G:\BALARF\MIPPA 2010\Claims Analysis\20" _
), Array("07;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;")), _
Destination:=Range("A1"))
.CommandText = Array( _
"SELECT " & Condition & ".`Total # of Participants`, " & Condition & ".State, HCC2.Plan, " & Condition & ".Age, " & Condition & ".HCC1, " & Condition & ".HCC2, " & Condition & ".HCC5, " & Condition & ".HCC7, " & Condition & ".`Total Member Months`, " & Condition & ".`Total Benefit Amount`, " & Condition & ".`# of Participants wit" _
, _
"h zero claim dollars`, " & Condition & ".Conditions" & Chr(13) & "" & Chr(10) & "FROM `G:\BALARF\MIPPA 2010\Claims Analysis\2007\hcc`." & Condition & " " & Condition & "" _
)
.Name = "Query from MS Access Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
Bookmarks