+ Reply to Thread
Results 1 to 4 of 4

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

  1. #1
    Ev
    Guest

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

    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




  2. #2
    Jeff Standen
    Guest

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

    Yep. Instead of

    Database=Master;

    use

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

    Jeff

    "Ev" <[email protected]> wrote in message
    news:OOP$f%[email protected]...
    > 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
    >
    >
    >




  3. #3
    Ev
    Guest

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

    Thanks Jeff

    "Jeff Standen" <[email protected]> wrote in message
    news:[email protected]...
    > Yep. Instead of
    >
    > Database=Master;
    >
    > use
    >
    > Database=" & Range("a1").value & ";
    >
    > Jeff
    >
    > "Ev" <[email protected]> wrote in message
    > news:OOP$f%[email protected]...
    >> 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
    >>
    >>
    >>

    >
    >




  4. #4
    Jeff Standen
    Guest

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

    No problem.

    Jeff

    "Ev" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks Jeff
    >
    > "Jeff Standen" <[email protected]> wrote in message
    > news:[email protected]...
    >> Yep. Instead of
    >>
    >> Database=Master;
    >>
    >> use
    >>
    >> Database=" & Range("a1").value & ";
    >>
    >> Jeff
    >>
    >> "Ev" <[email protected]> wrote in message
    >> news:OOP$f%[email protected]...
    >>> 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1