B
Brian
Howdy All,
This is part of what I hope to be a large project...
I have created a button, that when press, will prompt the user to browse for
an .mdb file.
I then run a query on that file to bring data into a new worksheet.
When I run it, opens the browse window and I browse and select my database
file, but then I get an error that says:
Could not find file 'C:\DBLocation.mdb'.
This is what I have:
Sub DataImport()
Dim DBLocation As String
DBLocation = Application.GetOpenFilename
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=DBLocation;DriverId=25;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;" _
)), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT `Combined Data`.`Assignee Mgr Name`, `Combined
Data`.Assignee,
`Combined Data`.`Instance#`, `Combined Data`.`SR Number`, `Combined
Data`.`SR
Reported Date`, `Combined Data`.`Task Number`, `Comb" _
, _
"ined Data`.`Task Actual Start Date`, `Combined Data`.`Task Actual
End
Date`, `Combined Data`.`Debrief Service Month`, `Combined Data`.`Debrief
Status`, `Combined Data`.`Task Type`, `Combined Data`.`Se" _
, _
"rvice Activity Code`, `Combined Data`.`Current Extended Labor
Cost`,
`Combined Data`.`Current Extended Travel Cost`, `Combined Data`.`Current
Extended Standard Cost`, `Combined Data`.`Current Extended" _
, _
" Total Cost`, `Combined Data`.LABOR, `Combined Data`.TRAVEL,
`Combined
Data`.`Ttl Hours`" & Chr(13) & "" & Chr(10) & "FROM `Combined Data`
`Combined
Data`" & Chr(13) & "" & Chr(10) & "WHERE (`Combined Data`.`Assignee Mgr
Name`='KLAVINS, EGONS E JR (ED)')" & Chr(13) & "" & Chr(10) & "" _
, "ORDER BY `Combined Data`.Assignee")
.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
I'm not sure what I missed...
Thanks,
Brian
This is part of what I hope to be a large project...
I have created a button, that when press, will prompt the user to browse for
an .mdb file.
I then run a query on that file to bring data into a new worksheet.
When I run it, opens the browse window and I browse and select my database
file, but then I get an error that says:
Could not find file 'C:\DBLocation.mdb'.
This is what I have:
Sub DataImport()
Dim DBLocation As String
DBLocation = Application.GetOpenFilename
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=DBLocation;DriverId=25;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;" _
)), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT `Combined Data`.`Assignee Mgr Name`, `Combined
Data`.Assignee,
`Combined Data`.`Instance#`, `Combined Data`.`SR Number`, `Combined
Data`.`SR
Reported Date`, `Combined Data`.`Task Number`, `Comb" _
, _
"ined Data`.`Task Actual Start Date`, `Combined Data`.`Task Actual
End
Date`, `Combined Data`.`Debrief Service Month`, `Combined Data`.`Debrief
Status`, `Combined Data`.`Task Type`, `Combined Data`.`Se" _
, _
"rvice Activity Code`, `Combined Data`.`Current Extended Labor
Cost`,
`Combined Data`.`Current Extended Travel Cost`, `Combined Data`.`Current
Extended Standard Cost`, `Combined Data`.`Current Extended" _
, _
" Total Cost`, `Combined Data`.LABOR, `Combined Data`.TRAVEL,
`Combined
Data`.`Ttl Hours`" & Chr(13) & "" & Chr(10) & "FROM `Combined Data`
`Combined
Data`" & Chr(13) & "" & Chr(10) & "WHERE (`Combined Data`.`Assignee Mgr
Name`='KLAVINS, EGONS E JR (ED)')" & Chr(13) & "" & Chr(10) & "" _
, "ORDER BY `Combined Data`.Assignee")
.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
I'm not sure what I missed...
Thanks,
Brian