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

Hello Everyone

I've got a workbook with a number of queries in it
I'm trying to update the database they connect to with
some code, as follows.

For some reason the connection strings are not being
updated. I presume there's something wrong with

With QT.Connection = NewConnectionString

Thanks in advance.

Matt

Sub UpdateConnectionStrings()
'This lists all the queries in a workbook by name
Dim WS As Worksheet
Dim QT As QueryTable
Dim iCount As Integer
For Each WS In ThisWorkbook.Worksheets
For Each QT In WS.QueryTables
' MsgBox "Worksheet Name: " & WS.Name
' MsgBox "Query Name: " & QT.Name
Debug.Print QT.Name & " " & QT.Connection
With QT.Connection = NewConnectionString

End With
Debug.Print QT.Name & " " & NewConnectionString
Debug.Print QT.Name & " " & QT.Connection

Next
Next
End Sub


Function NewConnectionString()

Dim strSQLDatabaseName, strSQLName, strSQLDatabase,
strLoginID, strPassword As String
Dim intFindDot As Integer

'Poplulate Login Strings
strLoginID = "SUN"
strPassword = "SUNSYS"
strSQLDatabaseName = "dbo.SUNDB426"

NewConnectionString = _
"ODBC;DSN=" & strSQLDatabaseName & ";UID=" & strLoginID
& ";PWD=" & strPassword & ";APP=SQL " & _
";AutoTranslate=No,"

End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Changing Connection Strings

Why not just use

With NewConnectionString

End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Matt" wrote in message
...
Hello Everyone

I've got a workbook with a number of queries in it
I'm trying to update the database they connect to with
some code, as follows.

For some reason the connection strings are not being
updated. I presume there's something wrong with

With QT.Connection = NewConnectionString

Thanks in advance.

Matt

Sub UpdateConnectionStrings()
'This lists all the queries in a workbook by name
Dim WS As Worksheet
Dim QT As QueryTable
Dim iCount As Integer
For Each WS In ThisWorkbook.Worksheets
For Each QT In WS.QueryTables
' MsgBox "Worksheet Name: " & WS.Name
' MsgBox "Query Name: " & QT.Name
Debug.Print QT.Name & " " & QT.Connection
With QT.Connection = NewConnectionString

End With
Debug.Print QT.Name & " " & NewConnectionString
Debug.Print QT.Name & " " & QT.Connection

Next
Next
End Sub


Function NewConnectionString()

Dim strSQLDatabaseName, strSQLName, strSQLDatabase,
strLoginID, strPassword As String
Dim intFindDot As Integer

'Poplulate Login Strings
strLoginID = "SUN"
strPassword = "SUNSYS"
strSQLDatabaseName = "dbo.SUNDB426"

NewConnectionString = _
"ODBC;DSN=" & strSQLDatabaseName & ";UID=" & strLoginID
& ";PWD=" & strPassword & ";APP=SQL " & _
";AutoTranslate=No,"

End Function



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Changing Connection Strings

Hi Bob / Everyone

When I do that I get the same effect
i.e. Debug.Print QT.Name & " " & NewConnectionString
returns the same information before and after

With NewConnectionString

End With


Regards

Matt

-----Original Message-----
Why not just use

With NewConnectionString

End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Matt" wrote in

message
...
Hello Everyone

I've got a workbook with a number of queries in it
I'm trying to update the database they connect to with
some code, as follows.

For some reason the connection strings are not being
updated. I presume there's something wrong with

With QT.Connection = NewConnectionString

Thanks in advance.

Matt

Sub UpdateConnectionStrings()
'This lists all the queries in a workbook by name
Dim WS As Worksheet
Dim QT As QueryTable
Dim iCount As Integer
For Each WS In ThisWorkbook.Worksheets
For Each QT In WS.QueryTables
' MsgBox "Worksheet Name: " & WS.Name
' MsgBox "Query Name: " & QT.Name
Debug.Print QT.Name & " " & QT.Connection
With QT.Connection = NewConnectionString

End With
Debug.Print QT.Name & " " & NewConnectionString
Debug.Print QT.Name & " " & QT.Connection

Next
Next
End Sub


Function NewConnectionString()

Dim strSQLDatabaseName, strSQLName, strSQLDatabase,
strLoginID, strPassword As String
Dim intFindDot As Integer

'Poplulate Login Strings
strLoginID = "SUN"
strPassword = "SUNSYS"
strSQLDatabaseName = "dbo.SUNDB426"

NewConnectionString = _
"ODBC;DSN=" & strSQLDatabaseName & ";UID=" & strLoginID
& ";PWD=" & strPassword & ";APP=SQL " & _
";AutoTranslate=No,"

End Function



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Changing Connection Strings

because we don't change QT in this case?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Matt" wrote in message
...
Hi Bob / Everyone

When I do that I get the same effect
i.e. Debug.Print QT.Name & " " & NewConnectionString
returns the same information before and after

With NewConnectionString

End With


Regards

Matt

-----Original Message-----
Why not just use

With NewConnectionString

End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Matt" wrote in

message
...
Hello Everyone

I've got a workbook with a number of queries in it
I'm trying to update the database they connect to with
some code, as follows.

For some reason the connection strings are not being
updated. I presume there's something wrong with

With QT.Connection = NewConnectionString

Thanks in advance.

Matt

Sub UpdateConnectionStrings()
'This lists all the queries in a workbook by name
Dim WS As Worksheet
Dim QT As QueryTable
Dim iCount As Integer
For Each WS In ThisWorkbook.Worksheets
For Each QT In WS.QueryTables
' MsgBox "Worksheet Name: " & WS.Name
' MsgBox "Query Name: " & QT.Name
Debug.Print QT.Name & " " & QT.Connection
With QT.Connection = NewConnectionString

End With
Debug.Print QT.Name & " " & NewConnectionString
Debug.Print QT.Name & " " & QT.Connection

Next
Next
End Sub


Function NewConnectionString()

Dim strSQLDatabaseName, strSQLName, strSQLDatabase,
strLoginID, strPassword As String
Dim intFindDot As Integer

'Poplulate Login Strings
strLoginID = "SUN"
strPassword = "SUNSYS"
strSQLDatabaseName = "dbo.SUNDB426"

NewConnectionString = _
"ODBC;DSN=" & strSQLDatabaseName & ";UID=" & strLoginID
& ";PWD=" & strPassword & ";APP=SQL " & _
";AutoTranslate=No,"

End Function



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Changing Connection Strings

Hi Bob / Everyone

Exactly!
Any ideas on some code that WILL change connection string
for the queries?

Regards

Matt


-----Original Message-----
because we don't change QT in this case?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Matt" wrote in

message
...
Hi Bob / Everyone

When I do that I get the same effect
i.e. Debug.Print QT.Name & " " & NewConnectionString
returns the same information before and after

With NewConnectionString

End With


Regards

Matt

-----Original Message-----
Why not just use

With NewConnectionString

End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the

Purbecks
(remove nothere from the email address if mailing

direct)

"Matt" wrote in

message
...
Hello Everyone

I've got a workbook with a number of queries in it
I'm trying to update the database they connect to

with
some code, as follows.

For some reason the connection strings are not being
updated. I presume there's something wrong with

With QT.Connection = NewConnectionString

Thanks in advance.

Matt

Sub UpdateConnectionStrings()
'This lists all the queries in a workbook by name
Dim WS As Worksheet
Dim QT As QueryTable
Dim iCount As Integer
For Each WS In ThisWorkbook.Worksheets
For Each QT In WS.QueryTables
' MsgBox "Worksheet Name: " & WS.Name
' MsgBox "Query Name: " & QT.Name
Debug.Print QT.Name & " " & QT.Connection
With QT.Connection = NewConnectionString

End With
Debug.Print QT.Name & " " &

NewConnectionString
Debug.Print QT.Name & " " & QT.Connection

Next
Next
End Sub


Function NewConnectionString()

Dim strSQLDatabaseName, strSQLName, strSQLDatabase,
strLoginID, strPassword As String
Dim intFindDot As Integer

'Poplulate Login Strings
strLoginID = "SUN"
strPassword = "SUNSYS"
strSQLDatabaseName = "dbo.SUNDB426"

NewConnectionString = _
"ODBC;DSN=" & strSQLDatabaseName & ";UID=" &

strLoginID
& ";PWD=" & strPassword & ";APP=SQL " & _
";AutoTranslate=No,"

End Function


.



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Changing Connection Strings

Hi

Have a look at http://www.dicks-clicks.com/excel/ExternalData5.htm Check
out the hyperlink "Change the Database Location". This might be of some
help.

Cheers - Grant


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Changing Connection Strings

Hi Grant

Indeed it does

Thank you very much indeed

Regards

Matt


-----Original Message-----
Hi

Have a look at http://www.dicks-

clicks.com/excel/ExternalData5.htm Check
out the hyperlink "Change the Database Location". This

might be of some
help.

Cheers - Grant


.

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
find and replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
Changing and Adding data through ODBC connection Bob Excel Discussion (Misc queries) 0 November 3rd 08 05:04 PM
always recheck data connection library for latest connection strin FurmanGG Excel Discussion (Misc queries) 0 September 14th 07 04:48 PM
How to find number of pairs of strings from list of strings? greg_overholt Excel Worksheet Functions 5 January 27th 06 10:42 PM
Changing OLE DB connection Jam22171 Excel Discussion (Misc queries) 3 July 21st 05 01:04 PM


All times are GMT +1. The time now is 06:25 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"