473,779 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nested "With" Clauses?

I'm going over an application written by somebody else and have encountered what
looks to me like nested "With"s.

Is this something new with MS Access 2003 or am I losing it? Seems to me that
when I tried nesting "With" clauses in MS Access 2000 it was a no-no.

Some sample code - in which it looks like they're creating/populating a
..XLS spreadsheet. "Option Explicit" is not specified in the module...
------------------------------------------------------------------------------
Sub ptManagers()

Dim strSheetName As String
Dim oSheet As Object
Dim wksPivot As Object

Set oSheet = oBook.Sheets.Ad d
oSheet.Activate

strSheetName = "ptManagers "
oSheet.Name = strSheetName
Set wksPivot = oSheet

oBook.Worksheet s(oSourceSheet. Name).PivotTabl es("FlashPivotT able").PivotCac he.
_
CreatePivotTabl e TableDestinatio n:=wksPivot.Ran ge("A3"), _
tableName:="ptM anagersPivotTab le", DefaultVersion: =xlPivotTableVe rsion10

Set pvtTable = wksPivot.PivotT ables("ptManage rsPivotTable")

With pvtTable

' Specify page fields.

.PivotFields("G roup").Orientat ion = xlPageField
.PivotFields("G roup").CurrentP age = "Total"
.PivotFields("T ype").Orientati on = xlPageField

With .PivotFields("D ate")
.Orientation = xlPageField
.NumberFormat = "ddMMMyy"
End With

' Specify fields
.PivotFields("P roduct").Orient ation = xlRowField
.PivotFields("P ortfolio").Orie ntation = xlRowField

With .PivotFields("P ortfolio Base Rtn(%)")
.Orientation = xlDataField
.Position = 1
.NumberFormat = "0.0"
.Caption = ".Portfolio Base Rtn(%)"
End With
With .PivotFields("I ndex Base Rtn(%)")
.Orientation = xlDataField
.Position = 2
.NumberFormat = "0.0"
.Caption = ".Index Base Rtn(%)"
End With
With .PivotFields("S tock Select")
.Orientation = xlDataField
.Position = 3
.NumberFormat = "0.000"
.Caption = ".Stock Select"
End With
With .PivotFields("G roup Weight")
.Orientation = xlDataField
.Position = 4
.NumberFormat = "0.000"
.Caption = ".Group Weight"
End With
With .PivotFields("T otal")
.Orientation = xlDataField
.Position = 5
.NumberFormat = "0.000"
.Caption = (".Total")
End With
With .DataPivotField
.Orientation = xlColumnField
.Position = 1
End With

.ColumnGrand = False
.HasAutoFormat = False
.RowGrand = False

.PivotFields("P ortfolio").Auto Sort xlDescending, ".Total"
.PivotFields("P roduct").Subtot als = Array(False, False, False, False,
False, False, False, False, False, False, False, False)
End With

With oSheet
.Range("5:5").E ntireRow.Hidden = True
.Rows("6:6").Ro wHeight = 56.25
With .Range("A6:G6")
.Font.Bold = True
.Interior.Color Index = 1
.Interior.Patte rn = xlSolid
.Font.ColorInde x = 2
.HorizontalAlig nment = xlCenter
.VerticalAlignm ent = xlBottom
.WrapText = True
End With

.Columns("B:F") .ColumnWidth = 8.5
.Columns("A:A") .ColumnWidth = 12
.Columns("B:B") .ColumnWidth = 18.5

With .PageSetup
.LeftFooter = "&F" & Chr(10) & "&A"
.CenterFooter = "Page &P of &N"
.RightFooter = "&D"
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
.Activate
.DisplayAutomat icPageBreaks = False
End With

oXL.ActiveWindo w.DisplayGridli nes = False
oBook.ShowPivot TableFieldList = False
End Sub

------------------------------------------------------------------------------
--
PeteCresswell
May 12 '06
19 23214
"Lyle Fairfield" wrote
I'm glad; but there is nothing wrong with
nested withs. I have been using them since
before the turn of the century with zero problems.


Turn of which century? :-)

And, of course, your perception and memory far outclasses the average. Thus
you can be an example to, but not representative of us of the "hoi polloi".

I'm with David on the subject of nesting withs -- it makes the code hard to
read for us "lesser mortals."

Larry
May 13 '06 #11
"Lyle Fairfield" <ly***********@ aim.com> wrote in message
news:Xn******** *************** **********@216. 221.81.119...
"David W. Fenton" <XX*******@dfen ton.com.invalid > wrote in
news:Xn******** *************** ***********@127 .0.0.1:
I think it creates extremely bad code to nest WITH blocks. To me,
it's a sign of a bad programmer, as it's optimization that makes the
code much harder to read and understand.


I'm a bad programmer.


Yeh, man, don't nobody mess wid you cuz you de baddest dere is! :-)
May 13 '06 #12
I wouldn't agree with that at all. Nested with statements don't necessarily
lead to poor readability, the biggest cause of that is behemoth procedures.

In fact when I take over a project from someone else I frequently find
myself going through implementing nested withs in order to increase
readability as much as anything.
--

Terry Kreft
"David W. Fenton" <XX*******@dfen ton.com.invalid > wrote in message
news:Xn******** *************** ***********@127 .0.0.1...
"(PeteCresswell )" <x@y.Invalid> wrote in
news:6e******** *************** *********@4ax.c om:
Per Rick Brandt:
you must provide a fully qualified object reference in an inner
With block to any member of an object in an outer With block.


I'll bet that's what got me off on the notion that they were a
no-no.... i.e. tried it, got my hand slapped, didn't think about
it any more.


I think it creates extremely bad code to nest WITH blocks. To me,
it's a sign of a bad programmer, as it's optimization that makes the
code much harder to read and understand.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

May 13 '06 #13
BAD BAD LYLE FAIRFIELD
Wih apologies to Jim Croce

Well the South side of Chicago
Is the baddest part of town
And if you go down there you better just beware
Of a man named Lyle Fairfield
Now Lyle more than trouble
You see he stand about six foot four
All the downtown ladies call him treetop lover
All the men just call him sir
....
--

Terry Kreft
"Larry Linson" <bo*****@localh ost.not> wrote in message
news:3gg9g.1683 $_B5.51@trnddc0 1...
"Lyle Fairfield" <ly***********@ aim.com> wrote in message
news:Xn******** *************** **********@216. 221.81.119...
"David W. Fenton" <XX*******@dfen ton.com.invalid > wrote in
news:Xn******** *************** ***********@127 .0.0.1:
I think it creates extremely bad code to nest WITH blocks. To me,
it's a sign of a bad programmer, as it's optimization that makes the
code much harder to read and understand.


I'm a bad programmer.


Yeh, man, don't nobody mess wid you cuz you de baddest dere is! :-)

May 13 '06 #14
Lyle Fairfield <ly***********@ aim.com> wrote in
news:Xn******** *************** **********@216. 221.81.119:
"David W. Fenton" <XX*******@dfen ton.com.invalid > wrote in
news:Xn******** *************** ***********@127 .0.0.1:
I think it creates extremely bad code to nest WITH blocks. To me,
it's a sign of a bad programmer, as it's optimization that makes
the code much harder to read and understand.


I'm a bad programmer.


A regular participant in one of the other forums I participate in
regularly points out that code is going to be *read* more often that
it is *written*. Thus, optimizations of the *writing* of the code,
when they make the code more convoluted, are going to be much more
inefficient than any amount of verbosity.

Now, this is separate from the issue of performance. My feeling is
that WITH blocks can speed up certain kinds of looped operations,
since they create an implicit reference to a parent object rather
than having to resolve through both the parent object's collection
and that of whatever object you're looking for within the
collections of that parent object.

But, in general, the feeling of a need to nest WITHs seems to me to
be an erroneous compulsion, one that makes the code harder to
maintain.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
May 13 '06 #15
Per Larry Linson:

I'm with David on the subject of nesting withs -- it makes the code hard to
read for us "lesser mortals."


I must be among the "*Much* lesser..." because I even found myself stumbling
over the code in the "good" example in the OP.
--
PeteCresswell
May 13 '06 #16
rkc
Terry Kreft wrote:
I wouldn't agree with that at all. Nested with statements don't necessarily
lead to poor readability, the biggest cause of that is behemoth procedures.


Amen.
May 13 '06 #17
"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:JO******** ************@ka roo.co.uk...
I wouldn't agree with that at all. Nested with statements don't
necessarily
lead to poor readability, the biggest cause of that is behemoth
procedures.

In fact when I take over a project from someone else I frequently find
myself going through implementing nested withs in order to increase
readability as much as anything.


I may uh bin wrong. Youse may be de baddest ub all! Don' nobody mess wid
Terry now, cuz dat man think nestin' Withs make things easier.

Larry
May 14 '06 #18

<Officer Barbrady>
OK, Lets move along now folks, there's nothing to see here ...
<Officer Barbrady>
--

Terry Kreft
"Larry Linson" <bo*****@localh ost.not> wrote in message
news:cpL9g.367$ 343.134@trnddc0 6...
"Terry Kreft" <te*********@mp s.co.uk> wrote in message
news:JO******** ************@ka roo.co.uk...
I wouldn't agree with that at all. Nested with statements don't
necessarily
lead to poor readability, the biggest cause of that is behemoth
procedures.

In fact when I take over a project from someone else I frequently find
myself going through implementing nested withs in order to increase
readability as much as anything.


I may uh bin wrong. Youse may be de baddest ub all! Don' nobody mess wid
Terry now, cuz dat man think nestin' Withs make things easier.

Larry

May 15 '06 #19
"Terry Kreft" <te*********@mp s.co.uk> wrote
<Officer Barbrady>
OK, Lets move along now folks, there's nothing to see here ...
<Officer Barbrady>


<MUTTER_GRUMBLE > "Nested WIFs." </MUTTER_GRUMBLE>

(Shuffles off, shoulders slumped.)
May 15 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3165
by: ribchr00 | last post by:
Hi all, I would like to replace line breaks such '+' with '<br />'. Easy task. Problems start when I try to only replace lines that do not end with HTML tags. I tried preg_replace("/+/", "<br />\n") but this does not seem to work. An example to better understand what I would like to achieve: first line
15
2972
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting it. Simple database: I want to have a user enter Supply Orders (just for tracking purposes) by Item. The user may also enter a new item - "new" is a combination of Item, PartNumber and Vendor - they could have the
25
2591
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For example: with quitCommandButton .enabled = true .default = true end with
14
2126
by: Ivan Voras | last post by:
Hi, I'm looking for a construct that's similar to (Turbo) Pascal's "with" statement. I read about the Python's new "with" statement, but I was dissapointed to learn that it does something different (I still don't see how it's better than try..except..finally, but that's not my question). Is there something similar to what I want that's Pythonic enough? (If you're not familiar with Pascal, here's how it works:
2
37807
by: jmash | last post by:
Suppose I have the following string whch is part of an xml string: String s= "Script Id=&quot;Test&quot; " And I need to get s= "Script Id="Test" " Can anyone tell me how this can acheived? Thanks, jmash
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.