Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default ActiveSheet.QueryTables.Add using a File DSN

I have the following subroutine that runs on the activation of several
different worksheets in different workbooks. I would like to be able
to just reference the DSN file for login information rather than
explicitly set the server, username, and password in every single
workbook and worksheet. It would make it much easier to distribute
the workbook to several different users if all they had to do is edit
one file with a text editor.

Private Sub Worksheet_Activate()

Sheet3.Activate
Columns("A:D").Select
Selection.ClearContents

useDate = Range("H35").Value

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL
Server;SERVER=SQL_SERVER_1;UID=username;PWD=passwo rd;APP=Microsoft
Office XP" _
, Destination:=Range("A1"))
.CommandText = Array("exec stored_proc")
.Name = "TESTQUERY"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub

How would I set it up so that it would connect to the database just by
referencing the file at "C:\Program Files\Common Files\ODBC\Data
Sources\testquery.dsn"?

Thank you for any help.

Brian
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default ActiveSheet.QueryTables.Add using a File DSN

Untested, but you could try:

ODBC;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\testquery.dsn

--

(Brian Howenstein) wrote in message . com...
I have the following subroutine that runs on the activation of several
different worksheets in different workbooks. I would like to be able
to just reference the DSN file for login information rather than
explicitly set the server, username, and password in every single
workbook and worksheet. It would make it much easier to distribute
the workbook to several different users if all they had to do is edit
one file with a text editor.

Private Sub Worksheet_Activate()

Sheet3.Activate
Columns("A:D").Select
Selection.ClearContents

useDate = Range("H35").Value

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL
Server;SERVER=SQL_SERVER_1;UID=username;PWD=passwo rd;APP=Microsoft
Office XP" _
, Destination:=Range("A1"))
.CommandText = Array("exec stored_proc")
.Name = "TESTQUERY"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = False
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub

How would I set it up so that it would connect to the database just by
referencing the file at "C:\Program Files\Common Files\ODBC\Data
Sources\testquery.dsn"?

Thank you for any help.

Brian

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
With ActiveSheet.QueryTables.Add [email protected] Excel Programming 4 January 6th 04 04:58 PM
QueryTables Interrupt if URL is Down Steve Hieb Excel Programming 0 November 17th 03 10:07 PM
ActiveSheet.Name? Andrew Stedman Excel Programming 5 July 30th 03 01:17 PM
ActiveSheet Ron de Bruin Excel Programming 0 July 29th 03 04:59 PM


All times are GMT +1. The time now is 05:28 AM.

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

About Us

"It's about Microsoft Excel"