Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Variables in Query Strings

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 Macro1

With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DSN=Timberline Estimating Data;DBQ=G:
\Illigdbase1;CODEPAGE=1252;DictionaryMode=0;Standa rdMode=0;MaxColSupport=255;ShortenNames="
_
), Array("0;DatabaseType=2;")), Destination:=Range("A1"))
.CommandText = Array( "SELECT * FROM ""308 NORTH RODEO DR
GC2_PEE_ESTIMATE_COVERPG_SETUP""")
.Refresh BackgroundQuery:=False
End With

End Sub

I have successfully created functions that provide the folder path
(FolderFromPath) and the file name (GetEstimateName).

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 seem to be having trouble with the connection and query strings and
passing them to the With statement. The FolderFromPath variable does
not to work in the ConnString. The CoverpageQuery is passed to the
QueryString with single quotes. I'm not sure how to accomodate the
double quotes. Any help or suggestions would be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Variables in Query Strings

On Jan 10, 9:52*am, "m00n" wrote:
schreef in ...





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- Hide quoted text -

- Show quoted text -


Would you have any suggestions for the double quotes in the
QueryString or Coverpagequery
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning multiple text strings to variables buggy Excel Programming 0 January 5th 06 08:49 PM
Variables in a query Keith[_11_] Excel Programming 5 January 13th 05 09:15 AM
substitute strings with variables banavas Excel Programming 2 June 4th 04 01:29 PM
Complex Text Strings|Variables cogent Excel Programming 4 April 8th 04 02:45 AM
Converting strings to Sum worksheet function and control variables Spammastergrand Excel Programming 5 February 21st 04 05:12 PM


All times are GMT +1. The time now is 03:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"