473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.Add
oSheet.Activate

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

oBook.Worksheets(oSourceSheet.Name).PivotTables("F lashPivotTable").PivotCache.
_
CreatePivotTable TableDestination:=wksPivot.Range("A3"), _
tableName:="ptManagersPivotTable", DefaultVersion:=xlPivotTableVersion10

Set pvtTable = wksPivot.PivotTables("ptManagersPivotTable")

With pvtTable

' Specify page fields.

.PivotFields("Group").Orientation = xlPageField
.PivotFields("Group").CurrentPage = "Total"
.PivotFields("Type").Orientation = xlPageField

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

' Specify fields
.PivotFields("Product").Orientation = xlRowField
.PivotFields("Portfolio").Orientation = xlRowField

With .PivotFields("Portfolio Base Rtn(%)")
.Orientation = xlDataField
.Position = 1
.NumberFormat = "0.0"
.Caption = ".Portfolio Base Rtn(%)"
End With
With .PivotFields("Index Base Rtn(%)")
.Orientation = xlDataField
.Position = 2
.NumberFormat = "0.0"
.Caption = ".Index Base Rtn(%)"
End With
With .PivotFields("Stock Select")
.Orientation = xlDataField
.Position = 3
.NumberFormat = "0.000"
.Caption = ".Stock Select"
End With
With .PivotFields("Group Weight")
.Orientation = xlDataField
.Position = 4
.NumberFormat = "0.000"
.Caption = ".Group Weight"
End With
With .PivotFields("Total")
.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("Portfolio").AutoSort xlDescending, ".Total"
.PivotFields("Product").Subtotals = Array(False, False, False, False,
False, False, False, False, False, False, False, False)
End With

With oSheet
.Range("5:5").EntireRow.Hidden = True
.Rows("6:6").RowHeight = 56.25
With .Range("A6:G6")
.Font.Bold = True
.Interior.ColorIndex = 1
.Interior.Pattern = xlSolid
.Font.ColorIndex = 2
.HorizontalAlignment = xlCenter
.VerticalAlignment = 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
.DisplayAutomaticPageBreaks = False
End With

oXL.ActiveWindow.DisplayGridlines = False
oBook.ShowPivotTableFieldList = False
End Sub

------------------------------------------------------------------------------
--
PeteCresswell
May 12 '06 #1
19 23154
(PeteCresswell) wrote:
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.


VBA help from Access 2003
***********************
You can nest With statements by placing one With block within another. However,
because members of outer With blocks are masked within the inner With blocks,
you must provide a fully qualified object reference in an inner With block to
any member of an object in an outer With block.
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
May 12 '06 #2
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.
--
PeteCresswell
May 12 '06 #3
"(PeteCresswell)" <x@y.Invalid> wrote in
news:6e********************************@4ax.com:
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 12 '06 #4
Bri
(PeteCresswell) wrote:
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.


You can nest 'With' statements in AC97 as well.

It is only really useful in a few situations. It can make the code more
difficult to follow unless you use consistant indenting. Your example is
a good example of using it right, IMO, but it is easy to do it wrong,
particulatly when you need to refer to a 'parent' object within the
nest. 'With' allows the code to run more efficiently, but with today's
PCs its not likely to be a noticable increase in speed.

--
Bri

May 12 '06 #5
Per David W. Fenton:

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.


Excellent. Now I feel better.... -)
--
PeteCresswell
May 12 '06 #6
rkc
David W. Fenton wrote:
"(PeteCresswell)" <x@y.Invalid> wrote in
news:6e********************************@4ax.com:

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.


No more so than nested anything else.


May 12 '06 #7
rkc <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in
news:I%******************@twister.nyroc.rr.com:
David W. Fenton wrote:
"(PeteCresswell)" <x@y.Invalid> wrote in
news:6e********************************@4ax.com:
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.


No more so than nested anything else.


But that is logically necessary.

And, of course, I try to avoid complex If/Then/Else nesting when
possible, in any case, as it seems to me to be a clue that there is
logic/design problem.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
May 12 '06 #8
"David W. Fenton" <XX*******@dfenton.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.

--
Lyle Fairfield
May 13 '06 #9
"(PeteCresswell)" <x@y.Invalid> wrote in
news:kq********************************@4ax.com:
Per David W. Fenton:

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.


Excellent. Now I feel better.... -)


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.

--
Lyle Fairfield
May 13 '06 #10
"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.8 1.119...
"David W. Fenton" <XX*******@dfenton.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*******@dfenton.com.invalid> wrote in message
news:Xn**********************************@127.0.0. 1...
"(PeteCresswell)" <x@y.Invalid> wrote in
news:6e********************************@4ax.com:
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*****@localhost.not> wrote in message
news:3gg9g.1683$_B5.51@trnddc01...
"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:Xn*********************************@216.221.8 1.119...
"David W. Fenton" <XX*******@dfenton.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.8 1.119:
"David W. Fenton" <XX*******@dfenton.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*********@mps.co.uk> wrote in message
news:JO********************@karoo.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*****@localhost.not> wrote in message
news:cpL9g.367$343.134@trnddc06...
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:JO********************@karoo.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*********@mps.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
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...
15
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...
25
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...
14
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...
2
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? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.