473,769 Members | 2,124 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 #1
19 23211
(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.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 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.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.


No more so than nested anything else.


May 12 '06 #7
rkc <rk*@rochester. yabba.dabba.do. rr.bomb> wrote in
news:I%******** **********@twis ter.nyroc.rr.co m:
David W. Fenton wrote:
"(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.


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*******@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.

--
Lyle Fairfield
May 13 '06 #9
"(PeteCresswell )" <x@y.Invalid> wrote in
news:kq******** *************** *********@4ax.c om:
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

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

Similar topics

3
3164
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
2590
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
37796
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
9583
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
10039
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...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8869
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...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
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.