The simpliest method is to manually create a new query. Select the database
from new server and pick any table. Then press next until Finish appears.
then on finish menu select "View Data or edit query in Microsoft Query". On
the Query menu select View - SQL. Copy the SQL from the workbook "A2" cell
and paste into SQL. close Query tool and follow remaining menues.
--------------------------------------------------------------------------------------------
Method 2 would be to use the macro below. The SQL statement was very long
so I had to make it into 3 peices.
Here is the data taken from cell A2
SELECT `0215 & 0064 parts received`.ID, `0215 & 0064 parts
received`.Program, `0215 & 0064 parts received`.`Procurement Part Number`,
`0215 & 0064 parts received`.`Upscreen Part Number`, `0215 & 0064 parts
received`.`Date Code`, `0215 & 0064 parts received`.`Date Received`, `0215 &
0064 parts received`.`Lot Review Date`, `0215 & 0064 parts received`.`Drawing
Revision`
FROM `C:\TEMP\PMI Part Log`.`0215 & 0064 parts received` `0215 & 0064 parts
received`
I add double quotes arount the strings. Also any data posted at this site
add a return after 80 characters so you would have to remove these extra
returns. SQL 1 - 3 are one line each on my PC. the SQL above on my PC is
one line. the SQL has to be shorten because the server will not recognize
long lines. Also in the CommandText statement below I added commas between
the 3 SQL statements.
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 12/1/2008 by jwarburg
'
Sql1 = "SELECT `0215 & 0064 parts received`.ID, `0215 & 0064 parts
received`.Program, `0215 & 0064 parts received`.`Procurement Part Number`,
`0215 & 0064 parts received`.`Upscreen Part Number`, `0215 & 0064 "
Sql2 = "parts received`.`Date Code`, `0215 & 0064 parts received`.`Date
Received`, `0215 & 0064 parts received`.`Lot Review Date`, `0215 & 0064 parts
received`.`Drawing Revision`" & Chr(13) & "" & Chr(10) & "FROM `C:\TEMP\PMI
Part Log`."
Sql3 = "`0215 & 0064 parts received` `0215 & 0064 parts received`"
'
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;" & _
"DBQ=C:\TEMP\PMI Part Log.mdb;" & _
"DefaultDir=C:\TEMP;DriverId=25;" & _
"FIL=MS Access;" & _
"MaxBufferSize=2048;" & _
"PageTimeout"), Array("=5;")), Destination:=Range("A1"))
.CommandText = Array(Sql1, Sql2, Sql3)
.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