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

Two questions
The below works is everything needed?
What does the last "with" statement really do??

Sub GetValues()

Dim strDate As String
strDate = Format(shtInput.Range("flyerdate"), "yyyy-mm-dd")

With ActiveWorkbook.Connections("Query from DB2P").ODBCConnection
.BackgroundQuery = False
.CommandText = "SELECT TAYVPHIS_0.PERF_AS_OF_DT, " & _
"TAYVPHIS_0.PROD_NUM, " & _
"TAYVPHIS_0.INV_MED_CD, " & _
"TAYVPHIS_0.SUR_CHRG_IND, " & _
"TAYVPHIS_0.PERF_SINCE_INCEP, " & _
"TAYVPHIS_0.PERF_SINCE_INCLU, " & _
"TAYVPHIS_0.PERF_10_YR, " & _
"TAYVPHIS_0.PERF_5_YR, " & _
"TAYVPHIS_0.PERF_1_YR, " & _
"TAYVPHIS_0.PERF_3_MO" & Chr(13) & "" & Chr(10) & _
"FROM PRDDB2.TAYVPHIS TAYVPHIS_0" & Chr(13) & "" & Chr(10) & _
"WHERE (TAYVPHIS_0.PERF_AS_OF_DT={d '" & strDate & "' })"
.CommandType = xlCmdSql
.Connection = _

"ODBC;DSN=XXXX;UID=XXXXXX;IpAddress=XXXXXX;TcpPort =446;Location=xxxxxx;"
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Query from DB2P")
.Name = "Query from DB2P"
.Description = ""
End With
ActiveWorkbook.Connections("Query from DB2P").Refresh
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Condensing code


I haven't looked at the material for your first question, but to quickly
answer your second question... the With statement is providing the object
that the .Name and .Description (notice the "dots" in front of them) refers
back to (which is the main purpose of the With statement... it relieves you
of having to continually type the object over and over again for each
property or method referencing that object).

--
Rick (MVP - Excel)


"Brad" wrote in message
...
Two questions
The below works is everything needed?
What does the last "with" statement really do??

Sub GetValues()

Dim strDate As String
strDate = Format(shtInput.Range("flyerdate"), "yyyy-mm-dd")

With ActiveWorkbook.Connections("Query from DB2P").ODBCConnection
.BackgroundQuery = False
.CommandText = "SELECT TAYVPHIS_0.PERF_AS_OF_DT, " & _
"TAYVPHIS_0.PROD_NUM, " & _
"TAYVPHIS_0.INV_MED_CD, " & _
"TAYVPHIS_0.SUR_CHRG_IND, " & _
"TAYVPHIS_0.PERF_SINCE_INCEP, " & _
"TAYVPHIS_0.PERF_SINCE_INCLU, " & _
"TAYVPHIS_0.PERF_10_YR, " & _
"TAYVPHIS_0.PERF_5_YR, " & _
"TAYVPHIS_0.PERF_1_YR, " & _
"TAYVPHIS_0.PERF_3_MO" & Chr(13) & "" & Chr(10) & _
"FROM PRDDB2.TAYVPHIS TAYVPHIS_0" & Chr(13) & "" & Chr(10) & _
"WHERE (TAYVPHIS_0.PERF_AS_OF_DT={d '" & strDate & "' })"
.CommandType = xlCmdSql
.Connection = _

"ODBC;DSN=XXXX;UID=XXXXXX;IpAddress=XXXXXX;TcpPort =446;Location=xxxxxx;"
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Query from DB2P")
.Name = "Query from DB2P"
.Description = ""
End With
ActiveWorkbook.Connections("Query from DB2P").Refresh
End Sub


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
Condensing VBA code Brad Excel Discussion (Misc queries) 3 September 9th 09 05:51 PM
Condensing working code Brad Excel Programming 3 November 20th 08 02:00 PM
Condensing Code steve Excel Programming 1 August 23rd 06 08:37 PM
Need help condensing with-end with code excelnut1954 Excel Programming 2 May 1st 06 03:49 PM
Trouble Condensing Code Ikaabod Excel Programming 3 April 11th 06 09:53 PM


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