Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default OLEDBConnection Properties

How does one specify OLEDBConnection properties and then use it to create a
QueryTable? The idea is to create a Query Table based on data retrieved via
an OLE DB driver and to update a pivot table in another sheet based on the
created QT (the latter I can do with no problems). The following does not
seem to work, since there is no way that I can find to set a reference to the
actual connection.

Thanx,
Sergey

Dim cn As OLEDBConnection
Dim qt As QueryTable
Dim sqlstring As String

Worksheets("Sheet2").Activate

For Each qt In ActiveSheet.QueryTables
qt.Delete
Next

Dim dtFrom As String
Dim dtTo As String
dtFrom = <set parm value
dtTo = <set parm value

sqlstring = <some SQL statement using the above parms

<how do I set the reference to cn???

With cn
.AlwaysUseConnectionFile = False
.BackgroundQuery = False
.CommandText = sqlstring
.CommandType = xlCmdSql
.Connection = "OLEDB;Provider=IBMDA400;" & _
"DSN=DSNNAME;" & _
"UID=USER;PWD=PASSWORD;"
.EnableRefresh = False
.MaintainConnection = True
.RefreshOnFileOpen = False
.RefreshPeriod = 0
.RetrieveInOfficeUILang = False
.RobustConnect = xlNever
'.SavePassword = True
.ServerCredentialsMethod = CredentialsMethodIntegrated
End With


With ActiveSheet.QueryTables.Add( _
Connection:=cn, _
Destination:=Range("A1"))
.Name = "Query_Name"
.AdjustColumnWidth = True
.BackgroundQuery = False
.EnableEditing = False
.EnableRefresh = True
.FieldNames = True
.PreserveColumnInfo = False
.PreserveFormatting = True
.RefreshPeriod = 0
.RefreshStyle = xlInsertDeleteCells
.SaveData = False

.Refresh

End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default OLEDBConnection Properties

Nevermind. I went with just refreshing the existing querytable and
connection, not the ideal situation, but oh well.



"krysolov" wrote:

How does one specify OLEDBConnection properties and then use it to create a
QueryTable? The idea is to create a Query Table based on data retrieved via
an OLE DB driver and to update a pivot table in another sheet based on the
created QT (the latter I can do with no problems). The following does not
seem to work, since there is no way that I can find to set a reference to the
actual connection.

Thanx,
Sergey

Dim cn As OLEDBConnection
Dim qt As QueryTable
Dim sqlstring As String

Worksheets("Sheet2").Activate

For Each qt In ActiveSheet.QueryTables
qt.Delete
Next

Dim dtFrom As String
Dim dtTo As String
dtFrom = <set parm value
dtTo = <set parm value

sqlstring = <some SQL statement using the above parms

<how do I set the reference to cn???

With cn
.AlwaysUseConnectionFile = False
.BackgroundQuery = False
.CommandText = sqlstring
.CommandType = xlCmdSql
.Connection = "OLEDB;Provider=IBMDA400;" & _
"DSN=DSNNAME;" & _
"UID=USER;PWD=PASSWORD;"
.EnableRefresh = False
.MaintainConnection = True
.RefreshOnFileOpen = False
.RefreshPeriod = 0
.RetrieveInOfficeUILang = False
.RobustConnect = xlNever
'.SavePassword = True
.ServerCredentialsMethod = CredentialsMethodIntegrated
End With


With ActiveSheet.QueryTables.Add( _
Connection:=cn, _
Destination:=Range("A1"))
.Name = "Query_Name"
.AdjustColumnWidth = True
.BackgroundQuery = False
.EnableEditing = False
.EnableRefresh = True
.FieldNames = True
.PreserveColumnInfo = False
.PreserveFormatting = True
.RefreshPeriod = 0
.RefreshStyle = xlInsertDeleteCells
.SaveData = False

.Refresh

End With

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
OleDBConnection.Open() blocks with 100% CPU Alexander Pachwald Excel Programming 0 February 13th 07 03:55 PM
Problem opening Excel 2007 file from OleDbConnection Dave Jenkins Excel Programming 1 October 24th 06 11:01 PM
Properties transferring from excel cells to word file properties lubo Excel Programming 4 July 12th 05 11:24 AM
Properties of a jpg Michael Singmin Excel Programming 3 June 11th 05 11:45 AM


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

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"