Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Can't change connection property on querytable

I have a Data Import set as a connection to another spreadsheet.

I'd like to be able to change the connected spreadsheet to another
spreadsheet, but nothing I do seems to change the connection string.

Here is the code:

With Sheets(1).QueryTables(1)
MsgBox .Connection
.Connection = Array(connect1, Range("path"), Range("File"),
connect2, connect3)
MsgBox .Connection
.CommandType = xlCmdSql
.CommandText = Array( "SELECT [F1], [F2 FROM [Combined File$] )
.Refresh BackgroundQuery:=False
End With

The msgbox shows me that the connection string is not being changed.
I can make the change manually just by editing the connection directly.
But in code, I can't make it happen. I've diddled with various other
properties (SourceDataFile, maintainconnection, enableediting, etc) but
nothing works.

Help
(Excel 2003)

The full connection string is:
Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Documents and
Settings\me\Combined File Dec 2008.xls;Mode=Share Deny Write;Extended
Properties="HDR=YES;";Jet OLEDB:System database="";Jet OLEDB:Registry
Path="";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet
OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet
OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet
OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet
OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Can't change connection property on querytable

A connection can't be change. You have to delete the old table and add a new
table. You can get the SQL (the command text portion of gthe query) and
change the SQL, but not the connection.

"makulski" wrote:

I have a Data Import set as a connection to another spreadsheet.

I'd like to be able to change the connected spreadsheet to another
spreadsheet, but nothing I do seems to change the connection string.

Here is the code:

With Sheets(1).QueryTables(1)
MsgBox .Connection
.Connection = Array(connect1, Range("path"), Range("File"),
connect2, connect3)
MsgBox .Connection
.CommandType = xlCmdSql
.CommandText = Array( "SELECT [F1], [F2 FROM [Combined File$] )
.Refresh BackgroundQuery:=False
End With

The msgbox shows me that the connection string is not being changed.
I can make the change manually just by editing the connection directly.
But in code, I can't make it happen. I've diddled with various other
properties (SourceDataFile, maintainconnection, enableediting, etc) but
nothing works.

Help
(Excel 2003)

The full connection string is:
Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Documents and
Settings\me\Combined File Dec 2008.xls;Mode=Share Deny Write;Extended
Properties="HDR=YES;";Jet OLEDB:System database="";Jet OLEDB:Registry
Path="";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet
OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet
OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet
OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet
OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Can't change connection property on querytable

I was rather coming to that conclusion. The helps file though <ido</i say
that connection is read/write. Nasty.

I've tried deleting the dataquery and then readding it with the same
details, but then I get an error message that says:
"A query already exists with that name".
Even though sheets(1).querytables.count replies "0" there still seems to
be some junk holding on. Do you have an example of the proper clean up
needed to delete then re-add?
Thanks.

"Joel" wrote:

A connection can't be change. You have to delete the old table and add a new
table. You can get the SQL (the command text portion of the query) and
change the SQL, but not the connection.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Can't change connection property on querytable

OK, I got it to work.
I recorded my changing of the connection string, then I replaced the
recorded file name with the variables. This works:

..Connection = Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" _
, Range("path"), Range(Period & "File"), _
";Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet
OLEDB:System database="""";Jet OLEDB:Registry " _
, _
"Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking
Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Tra" _
, _
"nsactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create
System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB" _
, _
":Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without
Replica Repair=False;Jet OLEDB:SFP=False" _
)

I thought this rather ugly, so I rearranged it a bit into this. This
doesn't work. There must be some subtle problem with this array statement.
SInce I can't see why this doesn't work, I'll revert to the uglier version
and just leave it at that.

Const connect1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;User
ID=Admin;Data Source="
Const connect2 As String = ";Mode=Share Deny Write;Extended
Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry
Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet
OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;"
Const connect3 As String = "Jet OLEDB:New Database Password="""";Jet
OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;Jet OLEDB:SFP=False"
..Connection = Array(connect1, Range("path"), Range(Period & "File"),
connect2, connect3)
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Can't change connection property on querytable

I don't know why you need all the parameters. try something like the code
below. Not sure that it works. I usally find with queries there is a hidden
carriage return thagt I miss when I tried to get rid of the rats nest in a
recorded macro. I usually atempt what you are doing an spend hours trying to
get the simplified code to work. Part of the problem is the command line in
the query have a maximum number of characters before you have to have a
semicolon or comma). the original code has some weird syntx that I'm not
sure even works.


..Connection = Array( _
"OLEDB;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"User ID=Admin;" & _
"Data Source=" & Range("path") & Range(Period & "File");" _
"Mode=Share Deny Write;" & _
"Extended Properties=""HDR=YES)


"makulski" wrote:

OK, I got it to work.
I recorded my changing of the connection string, then I replaced the
recorded file name with the variables. This works:

.Connection = Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" _
, Range("path"), Range(Period & "File"), _
";Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet
OLEDB:System database="""";Jet OLEDB:Registry " _
, _
"Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking
Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Tra" _
, _
"nsactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create
System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB" _
, _
":Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without
Replica Repair=False;Jet OLEDB:SFP=False" _
)

I thought this rather ugly, so I rearranged it a bit into this. This
doesn't work. There must be some subtle problem with this array statement.
SInce I can't see why this doesn't work, I'll revert to the uglier version
and just leave it at that.

Const connect1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;User
ID=Admin;Data Source="
Const connect2 As String = ";Mode=Share Deny Write;Extended
Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry
Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet
OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;"
Const connect3 As String = "Jet OLEDB:New Database Password="""";Jet
OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=False;Jet OLEDB:SFP=False"
.Connection = Array(connect1, Range("path"), Range(Period & "File"),
connect2, connect3)

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
querytable connection fails in Excel 2007 kk45 Excel Programming 0 March 19th 08 03:41 PM
QueryTable connection using ADO Recordset jfs Excel Programming 3 November 27th 06 01:54 AM
querytable connection TxRaistlin Excel Programming 2 February 9th 05 01:49 PM
Find the contents of a Connection property of the QueryTable objec SPYREN Excel Programming 4 October 28th 04 04:03 PM


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