• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

access: explanation of code

I have been given the code below which works as advertised in restricting textboxes in a report to boxes which have text in them.

Four mini questions: what is formatcount in plain english please
and how does it operate in relation to sections and
what does section (0) mean?
what would section (1) mean?
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim ctl As Control
For Each ctl In Me.Section(0).Controls
    ctl.Visible = Not IsNull(ctl)
Next
End Sub

Open in new window

0
topUKlawyer
Asked:
topUKlawyer
  • 5
  • 3
  • 2
  • +1
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Here is the info on Section ... which refers to an Area of the Form or Report, such as the Form Header/Footer, Detail section ... etc: (From Help)

Section Property
See AlsoApplies ToExampleSpecificsSection property as it applies to controls on a form or report.

You can identify these controls by the section of a form or report where the control appears. Read/write Integer.

expression.Section
expression    Required. An expression that returns one of the above objects.

Remarks
For controls, you can use the Section property to determine which section of a form or report a control is in.

Section property as it applies to the Form and Report objects.

You can use the Section property to identify a section of a form or report and provide access to the properties of that section. Read-only Section object.

expression.Section(Index)
expression    Required. An expression that returns one of the above objects.

Index   Required Variant. The section number or name.

Remarks
The Section property corresponds to a particular section. You can use the following constants listed below. It is recommended that you use the constants to make your code easier to read.

Setting Constant Description
0 acDetail Form detail section or report detail section
1 acHeader Form or report header section
2 acFooter Form or report footer section
3 acPageHeader Form or report page header section
4 acPageFooter Form or report page footer section
5 acGroupLevel1Header Group-level 1 header section (reports only)
6 acGroupLevel1Footer Group-level 1 footer section (reports only)
7 acGroupLevel2Header Group-level 2 header section (reports only)
8 acGroupLevel2Footer Group-level 2 footer section (reports only)

If a report has additional group-level sections, the header/footer pairs are numbered consecutively beginning with 9.
0
 
Rey Obrero (Capricorn1)Commented:
Section(0) is the Detail section part of the report
Section(1) is the header section part of the report
Section(2) is the footer section part of the report
0
 
TerrySolanenCommented:
1) FormatCount (and Cancel) are both variables that are "passed into" the subroutine (sub).  In most subroutines, variables that are passed into the subroutine are used...but neither variable is used, so you could delete the "(Cancel As Integer, FormatCount As Integer)" wording from the first line, and everything will work the same.

2) Since neither variable is used, they don't operate at all in relation to sections.

3) On the form or report this code is for, there are (or could be) multiple sections.  "Section(0)" is referring to the first one (the form detail section).

4) Section(1) would refer to the second one, aka the form header.

So, in summary, this code is a lot longer than it needs to be.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Here is the Help Info on FormatCount:

"You can use the FormatCount property to determine the number of times the OnFormat property has been evaluated for the current section on a report. Read/write Integer.

expression.FormatCount
expression    Required. An expression that returns one of the objects in the Applies To list.

Microsoft Access increments the FormatCount property each time the OnFormat property setting is evaluated for the current section. As the next section is formatted, Microsoft Access resets the FormatCount property to 1.

Under some circumstances, Microsoft Access formats a section more than once. For example, you might design a report in which the KeepTogether property for the detail section is set to Yes. When Microsoft Access reaches the bottom of a page, it formats the current detail section once to see if it will fit. If it doesn't fit, Microsoft Access moves to the next page and formats the detail section again. In this case, the setting for the FormatCount property for the detail section is 2 because it was formatted twice before it was printed.

You can use the FormatCount property to ensure that an operation that affects formatting gets executed only once for a section."

==== ====

mx
0
 
topUKlawyerAuthor Commented:
thanks.
how do I get to Format Count property.

thru help section I guess but can I get to it through Object browser and clicking the objects methods etc or am I barking up the wrong tree.... or just barking generally...

0
 
topUKlawyerAuthor Commented:
sokay i got it through the code window

is that right?
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
For example:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim ctl As Control
For Each ctl In Me.Section(0).Controls
    ctl.Visible = Not IsNull(ctl)
Next
Dim x As Integer
x=FormatCount
Debug.Print x
End Sub

You can then see the value of the Format Count in the VBA immediate window - each time it changes.

mx
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"is that right?"
More or less ... see my example above.

mx
0
 
TerrySolanenCommented:
What is it that you are trying to accomplish by getting to the FormatCount?  It's not something that you can set, if that's what you are asking.

Basically, it's a behind the scenes value that MS Access updates. (based on what DatabaseMX references)

As it applies to your code in this post, it's not used.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
I can't even remember the last time I need to use that property.  But, for some complex reports I suspect it would be handy.

mx
0
 
topUKlawyerAuthor Commented:
Thanks to everyone
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now