Link to home
Start Free TrialLog in
Avatar of Richard
Richard

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of TerrySolanen
TerrySolanen

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.
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
Avatar of Richard

ASKER

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

Avatar of Richard

ASKER

sokay i got it through the code window

is that right?
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
"is that right?"
More or less ... see my example above.

mx
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.
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
Avatar of Richard

ASKER

Thanks to everyone