mcgj said:
Does anyone know if you can mess with the formatting of a report
using VBA when it loads to modify the widths its columns?
I have a report that I have set up that has four columns on it. The
first column has labels that identify what can be found in that row.
The subsequent three columns then have numbers that are test
results. As you can imagine the labels require many more characters
than the results so if I could change the width of column 2, 3 & 4 I
could get more results on a page and that would be great!
Any help would be greatly appreciated.
I think you can play with the Width property of the controls, both
in the reports on open event, and the on format event of the section
in which the controls reside.
Try for instance making the control very small, then use something
like this in the forms on open event
Me!txtNameOfFirstControl.Width = 2500
Or in the on format event of the Detail section
Me!txtNameOfFirstControl.Width = _
Len(Me!txtNameOfFirstControl.Value & vbnullstring) * 100
To play with the left position of the control - i e where it "starts",
try playing with the .Left property of the control (more detail
section=
Me!txtNameOfSecondControl.Left = Me!txtNameOfFirstControl.Width _
+ Me!txtNameOfControl.Left + 100
Note that the measures are in Twips (567 twips per cm, 1440 twips
per inch).
I think that if you wish to do something like this in the reports
on open event, you'll probably need to open a recordset based on the
recordsource of the report, loop it, and find the largest text, then
apply some calculations. Here is some more air code.
dim rs as dao.recordset
dim lngLen as long
const clngAdd as long = 100 ' factor
set rs = currentdb.openrecordset(me.recordcource)
do while not rs.eof
if len(rs.fields("NameOfField").value) > lngLen then
lngLen = len(rs.fields("NameOfField").value)
end if
.movenext
loop
rs.close
set rs = nothing
Me!txtNameOfFirstControl.Width = lngLen * clngAdd
Me!txtNameOfSecondControl.Left = Me!txtNameOfFirstControl.Width _
+ Me!txtNameOfControl.Left + 100
I've only used approximates like this, when the need arose. For more
precise measuring, if needed, here are a couple of links (watch for
linebreaks)
http://www.lebans.com/textwidth-height.htm
http://groups.google.com/group/microsoft.public.vb.winapi/browse_frm/thread/a7bcbe490121763d/