Indenting details

G

Guest

I have a simple table and need a simple report. (there's other fields, just
keeping it simple)
WBS Description
1 ABC
1.1 DEF
1.2 XYZ
1.2.1 GHI
2 JKL
2.2 MNO
I need the report to indent (there are five levels of indenting (1.1.1.1.1))
and look like is:
WBS Description
1 ABC
1.1 DEF
1.2 XYZ
1.2.1 GHI
2 JKL
2.2 MNO
I've tried difference way but I'm not doing it right. Would appreciate
advice.

Thanks, Steve
 
M

Marshall Barton

Steve said:
I have a simple table and need a simple report. (there's other fields, just
keeping it simple)
WBS Description
1 ABC
1.1 DEF
1.2 XYZ
1.2.1 GHI
2 JKL
2.2 MNO
I need the report to indent (there are five levels of indenting (1.1.1.1.1))
and look like is:
WBS Description
1 ABC
1.1 DEF
1.2 XYZ
1.2.1 GHI
2 JKL
2.2 MNO
I've tried difference way but I'm not doing it right. Would appreciate
advice.


There's nothing builtin to Access to do that as simple
setting. However, you can use code to adjust the position
of each control.

First, declare a module level array to hold each control's
initial position:

Private alngLeft() As Long

Then use this kind of code in the report's Open event
procedure to initilize the array:

Dim ctl as Control
Dim k As Integer
ReDim alngLeft(Me.Section(0).Controls.Count - 1)
For Each ctl in Me.Section(0).Controls
alngLeft(k) = ctl.Left
k = k + 1
Next ctl

Then use code like this in the detail section's Format event
procedure:

Dim ctl As Control
Dim intLevel As Integer
Dim k As Integer

intLevel = Len(Me.WBS) - Len(Replace(Me.WBS, ".", ""))
For Each ctl In Me.Section(0).Controls
ctl.Left = alngLeft(k) + intLevel * 500
k = k + 1
Next ctl

The 500 is the numbe of twips (1440 per inch) that you want
to indent. Make sure there is plenty of room to the right
of the controls to accomodate the max amount of indents.
 
G

Guest

Marshall, I understand putting the code in the reports Open event and the
code in the detail's Format. But I don't understand or should say I don't
know what you mean by "declare a module level array to hold each control's
initial position: Private alngLeft() As Long". How would I do that?

Steve
 
M

Marshall Barton

A module level variable is one that is declared at the top
of the module, before any Function or Sub procedures. This
is needed because all procedures in the module can then use
the variable, i.e. one procedure can set the values and
another procedure in the same module can use the values.

If you use Public instead of Private, then the variable
would be available to all VBA procedures in your entire
application. The global nature of Public variables is
generally considered a bad practice and should be avoided,

This is distinctly different from Local variables. Local
variables are declared within a procedure and can only be
used by that procedure.

The concept of what can access a variable is called the
"Scope" of the variable and a general rule is that the
smaller the scope, the better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top