PC Review


Reply
Thread Tools Rate Thread

Change Database that MS Query points to based on cell value Excel

 
 
Ev
Guest
Posts: n/a
 
      29th May 2006
Hi All,
I have an excel spreadsheet which gets data from an SQL database via MS
query, I need to repeat exactly the same query for some 30 databases.
Is it possible to link the database name to a value in a cell using
Range(a1).Value or something similar?

Selection.QueryTable
.Connection = Array(Array( _


"ODBC;DSN=mysqldb;Description=mysqldb;UID=Password;PWD=Password;APP=Microso*ft
Office 2003;WSID=XYZ;DATABASE=Master;Network=DBMSSOCN" _
), Array(";AutoTranslate=No;QuotedId=No;AnsiNPW=No"))


.CommandText = Array( _
"SELECT GL00100.ACTNUMBR_1, GL00100.ACTNUMBR_2,
GL00100.ACTNUMBR_3, GL00100.ACTDESCR, GL00100.ACTALIAS,
Sum(GL10110.PERDBLNC) AS '$'" & Chr(13) & "" & Chr(10) & "FROM
[Range(a1).value & ".dbo.GL00100 GL00100, FROM [Range(a1).value
..dbo.GL10110 GL10110" & Chr(13) & "" & Chr(10) & "WHERE GL00100.ACTINDX
= GL10110.ACTINDX" & Chr(13) & "" & Chr(10)


Thanks



 
Reply With Quote
 
 
 
 
Jeff Standen
Guest
Posts: n/a
 
      1st Jun 2006
Yep. Instead of

Database=Master;

use

Database=" & Range("a1").value & ";

Jeff

"Ev" <(E-Mail Removed)> wrote in message
news:OOP$f%(E-Mail Removed)...
> Hi All,
> I have an excel spreadsheet which gets data from an SQL database via MS
> query, I need to repeat exactly the same query for some 30 databases.
> Is it possible to link the database name to a value in a cell using
> Range(a1).Value or something similar?
>
> Selection.QueryTable
> .Connection = Array(Array( _
>
>
> "ODBC;DSN=mysqldb;Description=mysqldb;UID=Password;PWD=Password;APP=Microso*ft
> Office 2003;WSID=XYZ;DATABASE=Master;Network=DBMSSOCN" _
> ), Array(";AutoTranslate=No;QuotedId=No;AnsiNPW=No"))
>
>
> .CommandText = Array( _
> "SELECT GL00100.ACTNUMBR_1, GL00100.ACTNUMBR_2,
> GL00100.ACTNUMBR_3, GL00100.ACTDESCR, GL00100.ACTALIAS,
> Sum(GL10110.PERDBLNC) AS '$'" & Chr(13) & "" & Chr(10) & "FROM
> [Range(a1).value & ".dbo.GL00100 GL00100, FROM [Range(a1).value
> .dbo.GL10110 GL10110" & Chr(13) & "" & Chr(10) & "WHERE GL00100.ACTINDX
> = GL10110.ACTINDX" & Chr(13) & "" & Chr(10)
>
>
> Thanks
>
>
>



 
Reply With Quote
 
Ev
Guest
Posts: n/a
 
      1st Jun 2006
Thanks Jeff

"Jeff Standen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Yep. Instead of
>
> Database=Master;
>
> use
>
> Database=" & Range("a1").value & ";
>
> Jeff
>
> "Ev" <(E-Mail Removed)> wrote in message
> news:OOP$f%(E-Mail Removed)...
>> Hi All,
>> I have an excel spreadsheet which gets data from an SQL database via MS
>> query, I need to repeat exactly the same query for some 30 databases.
>> Is it possible to link the database name to a value in a cell using
>> Range(a1).Value or something similar?
>>
>> Selection.QueryTable
>> .Connection = Array(Array( _
>>
>>
>> "ODBC;DSN=mysqldb;Description=mysqldb;UID=Password;PWD=Password;APP=Microso*ft
>> Office 2003;WSID=XYZ;DATABASE=Master;Network=DBMSSOCN" _
>> ), Array(";AutoTranslate=No;QuotedId=No;AnsiNPW=No"))
>>
>>
>> .CommandText = Array( _
>> "SELECT GL00100.ACTNUMBR_1, GL00100.ACTNUMBR_2,
>> GL00100.ACTNUMBR_3, GL00100.ACTDESCR, GL00100.ACTALIAS,
>> Sum(GL10110.PERDBLNC) AS '$'" & Chr(13) & "" & Chr(10) & "FROM
>> [Range(a1).value & ".dbo.GL00100 GL00100, FROM [Range(a1).value
>> .dbo.GL10110 GL10110" & Chr(13) & "" & Chr(10) & "WHERE GL00100.ACTINDX
>> = GL10110.ACTINDX" & Chr(13) & "" & Chr(10)
>>
>>
>> Thanks
>>
>>
>>

>
>



 
Reply With Quote
 
Jeff Standen
Guest
Posts: n/a
 
      2nd Jun 2006
No problem.

Jeff

"Ev" <(E-Mail Removed)> wrote in message
news:e$(E-Mail Removed)...
> Thanks Jeff
>
> "Jeff Standen" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Yep. Instead of
>>
>> Database=Master;
>>
>> use
>>
>> Database=" & Range("a1").value & ";
>>
>> Jeff
>>
>> "Ev" <(E-Mail Removed)> wrote in message
>> news:OOP$f%(E-Mail Removed)...
>>> Hi All,
>>> I have an excel spreadsheet which gets data from an SQL database via MS
>>> query, I need to repeat exactly the same query for some 30 databases.
>>> Is it possible to link the database name to a value in a cell using
>>> Range(a1).Value or something similar?
>>>
>>> Selection.QueryTable
>>> .Connection = Array(Array( _
>>>
>>>
>>> "ODBC;DSN=mysqldb;Description=mysqldb;UID=Password;PWD=Password;APP=Microso*ft
>>> Office 2003;WSID=XYZ;DATABASE=Master;Network=DBMSSOCN" _
>>> ), Array(";AutoTranslate=No;QuotedId=No;AnsiNPW=No"))
>>>
>>>
>>> .CommandText = Array( _
>>> "SELECT GL00100.ACTNUMBR_1, GL00100.ACTNUMBR_2,
>>> GL00100.ACTNUMBR_3, GL00100.ACTDESCR, GL00100.ACTALIAS,
>>> Sum(GL10110.PERDBLNC) AS '$'" & Chr(13) & "" & Chr(10) & "FROM
>>> [Range(a1).value & ".dbo.GL00100 GL00100, FROM [Range(a1).value
>>> .dbo.GL10110 GL10110" & Chr(13) & "" & Chr(10) & "WHERE GL00100.ACTINDX
>>> = GL10110.ACTINDX" & Chr(13) & "" & Chr(10)
>>>
>>>
>>> Thanks
>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Change cell colour based on text gfa tracey General Software 2 17th Mar 2011 10:10 AM
change cell/s into perfect squares in mm/points/pixels in Excel 20 Ferdinand Microsoft Excel Misc 1 20th Oct 2008 03:24 PM
Change fill color based on value of another cell in Excel =?Utf-8?B?Rm9yZW5zaWNBY2NvdW50YW50?= Microsoft Excel Programming 2 20th Dec 2005 06:08 PM
Query Database based on List in Excel =?Utf-8?B?Um9i?= Microsoft Excel Charting 0 26th May 2004 06:51 PM
Exporting data from Database to Excel based on query Ella Microsoft Excel Misc 0 30th Sep 2003 12:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:49 PM.