changing position and width of textfields with vba

F

Fred Mundel

hello,

is there any way to change the positions (left.coordinate) and width of
textfields with vba while opening a report?

Problem: i have 10 textfields and the user can decide, how many of them
should be printed. so they can say: print column 1,2,5,6 or 3,6,8 or
whatever. In the report i wanna change the position of the textfields so
in example one the field 1 start at left-position 0 and have a width of
maxwidth/4. In second example field 3 have to start at left-position 0
and should have the width of maxwidth/3.
it seems at the report-events if cant change that attributes while using
the report.

I tried a way of opening the report in design-modus (DoCmd.OpenReport
stDocName, acViewDesign), change all attributes of the textfields, save
the report and open it then in preview-modus. That would work, but i
think that will not work anymore if i switch the mdb to mde, because you
cant change reports in mde anymore...
Is there any other way to solve my problem?

greetings
fred
 
A

Allen Browne

Fred, use the Open event procedure of the report to do this.

You can set the properties of each text box in this event: Visible, Left,
Width, ...

You can even assign the Control Source (unless you are using Access 2007
which will crash if you try that.)
 
M

Marshall Barton

Fred said:
is there any way to change the positions (left.coordinate) and width of
textfields with vba while opening a report?

Problem: i have 10 textfields and the user can decide, how many of them
should be printed. so they can say: print column 1,2,5,6 or 3,6,8 or
whatever. In the report i wanna change the position of the textfields so
in example one the field 1 start at left-position 0 and have a width of
maxwidth/4. In second example field 3 have to start at left-position 0
and should have the width of maxwidth/3.
it seems at the report-events if cant change that attributes while using
the report.

I tried a way of opening the report in design-modus (DoCmd.OpenReport
stDocName, acViewDesign), change all attributes of the textfields, save
the report and open it then in preview-modus. That would work, but i
think that will not work anymore if i switch the mdb to mde, because you
cant change reports in mde anymore...
Is there any other way to solve my problem?


This isn't too dificult, but you definitely DO NOT want to
do it in design view. Use the report's Open event to adjust
the properties.

Assuming there is a form that specifies the fields to be
displayed??

It makes life a lot easier if you name the report text boxes
with a fixed prefix and a sequntially numbered suffix (e.g.
txt1,txt2, ...)

For k = 1 To Forms!txtnumberoffields
Me("txt" & k).Left = lngPos
lngPos = lngPos + Me.Width \ Forms!txtnumberoffields
Next
 
F

Fred Mundel

Many thanks, Allen and Marshall!
shame on me i havnt tried that event. works perfect. many thanks again.
 

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