PC Review


Reply
Thread Tools Rate Thread

Condensing code

 
 
Brad
Guest
Posts: n/a
 
      9th Dec 2008
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 With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      9th Dec 2008

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" <(E-Mail Removed)> wrote in message
news:8E795F59-DC79-4083-8232-(E-Mail Removed)...
> 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Condensing VBA code Brad Microsoft Excel Misc 3 9th Sep 2009 05:51 PM
Condensing working code Brad Microsoft Excel Programming 3 20th Nov 2008 02:00 PM
Condensing Code =?Utf-8?B?c3RldmU=?= Microsoft Excel Programming 1 23rd Aug 2006 08:37 PM
Need help condensing with-end with code excelnut1954 Microsoft Excel Programming 2 1st May 2006 03:49 PM
Trouble Condensing Code Ikaabod Microsoft Excel Programming 3 11th Apr 2006 09:53 PM


Features
 

Advertising
 

Newsgroups
 


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