View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
m00n[_2_] m00n[_2_] is offline
external usenet poster
 
Posts: 3
Default Variables in Query Strings


schreef in bericht
...
I am a novice at programming and I am sure there may be more efficient
ways to accomplish the same task but I am attempting to emulate a
recorded macro in Excel and substitute variables for the folder path
(blue) and the file name (green). The recorded macro is as follows:

Sub Macro2


GetEstimateName
FolderFromPath (strFullPath)
CoverpageQuery = GetEstimateName & "_PEE_ESTIMATE_COVERPG_SETUP"

' Connection String
ConnString = "ODBC;DSN=Timberline Estimating
Data;DBQ=FolderFromPath;" '

' Query String
QueryString = "SELECT * FROM CoverpageQuery"

With
ActiveSheet.QueryTables.Add(Connection:=Array(Arra y(ConnString),
Array("0;DatabaseType=2;")), Destination:=Range("A1"))
.CommandText = QueryString
.Refresh BackgroundQuery:=False
End With
End Sub



I think you should try it like this:

'Connection String
ConnString = "ODBC;DSN=Timberline Estimating
Data;DBQ=" & FolderFromPath