Go Back   Access World Forums > Microsoft Access Discussion > Reports

 
Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
Old 12-10-2008, 04:51 PM   #1
wiklendt
i recommend chocolate
 
wiklendt's Avatar
 
Join Date: Mar 2008
Location: Cobar, Australia
Posts: 1,746
Thanks: 13
Thanked 20 Times in 18 Posts
wiklendt is a jewel in the rough wiklendt is a jewel in the rough wiklendt is a jewel in the rough
grow label height with textbox height....

hey,

i have some VBA which is designed to find the maximum height of label and textbox control (i have changed the label into a textbox, but its function remains as a label: this was to faciliate the max height idea but i don't know that it's helped, actually), and then make the shorter one match the taller one such that the solid colour fill of the controls are nicely as tall as one another.

now, the VBA i'm using (found externally via google, modified slightly for my own purposes) i can get it to do the fill, but not the maximum height thing.

the logic is good (i think), but i'm suspicious whether the "OnFormat" event is the correct event to put this code - i think it's drawing the 'line' BEFORE the field is grown, and thus each field colour fill ends up looking just one line tall... (see attachment). the text is showing fine, it's just the height of the drawn line.

the other thing i was thinking was maybe my "find maximum height" code was incorrect - though i personally can find no flaw in it.

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'this code from http://www.eggheadcafe.com/software/aspnet/32844884/label-growing-problems.aspx
'major contributor: duanehooko

Dim intMaxHeight As Integer
Dim ctl As Control
Dim lngColourLabel, lngColourText As Long

lngColourLabel = rgb(204, 255, 153)  'pale green
lngColourText = rgb(236, 236, 236) 'pale grey

'Find tallest control in Detail section
For Each ctl In Me.Section(0).Controls
    If ctl.Height > intMaxHeight Then
        intMaxHeight = ctl.Height
    End If
Next

Me.DrawStyle = 6 'transparent border, solid fill

'Draw a box around each control in Detail according to its tag property
For Each ctl In Me.Section(0).Controls
    If ctl.Tag = "label" Then
        Me.Line (ctl.Left, ctl.Top)-Step(ctl.Width, intMaxHeight), lngColourLabel, BF
    End If

    If ctl.Tag = "text" Then
        Me.Line (ctl.Left, ctl.Top)-Step(ctl.Width, intMaxHeight), lngColourText, BF
    End If
Next

End Sub
any help will be appreciated. thanks.

just one last note: the label sometimes (you can see in the pdf) is the taller of the two, which is why i make VBA find the tallest control in the section before applying that height to both controls there.
Attached Files
File Type: pdf rptHorseMassage_Glossary.pdf (12.4 KB, 387 views)

__________________

Agnieszka


Access 2016 x32 | Win10 x64 Home
_________________________________
! a tutorial on
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
wiklendt is offline   Reply With Quote
Old 12-10-2008, 04:56 PM   #2
wiklendt
i recommend chocolate
 
wiklendt's Avatar
 
Join Date: Mar 2008
Location: Cobar, Australia
Posts: 1,746
Thanks: 13
Thanked 20 Times in 18 Posts
wiklendt is a jewel in the rough wiklendt is a jewel in the rough wiklendt is a jewel in the rough
Re: grow label height with textbox height....

ok, solved my own problem!!

the VBA worked in the "OnPrint" event :-D

hope this now will help anyone else trying to do this - it's a very elegant solution!
Attached Files
File Type: pdf rptHorseMassage_Glossary_good.pdf (12.7 KB, 564 views)
__________________

Agnieszka


Access 2016 x32 | Win10 x64 Home
_________________________________
! a tutorial on
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by wiklendt; 12-10-2008 at 06:27 PM.
wiklendt is offline   Reply With Quote
Old 12-10-2008, 06:01 PM   #3
wiklendt
i recommend chocolate
 
wiklendt's Avatar
 
Join Date: Mar 2008
Location: Cobar, Australia
Posts: 1,746
Thanks: 13
Thanked 20 Times in 18 Posts
wiklendt is a jewel in the rough wiklendt is a jewel in the rough wiklendt is a jewel in the rough
Re: grow label height with textbox height....

ok actually, here's something that i now want to do and am not sure how to go about it.

with the code above, this is to exist in several subreports i have in my database. i want to make a module with a "Function CtrlMaxHeight" to call in each OnPrint event where i want this funciton to work, BUT, when i put the code in (copy/paste), then try to run it by print previewing the report, access tells me i can't use "Me." in the code... how do i get around this so that i don't have to update it for every subreport i make?

__________________

Agnieszka


Access 2016 x32 | Win10 x64 Home
_________________________________
! a tutorial on
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
wiklendt is offline   Reply With Quote
Old 12-11-2008, 02:43 AM   #4
wiklendt
i recommend chocolate
 
wiklendt's Avatar
 
Join Date: Mar 2008
Location: Cobar, Australia
Posts: 1,746
Thanks: 13
Thanked 20 Times in 18 Posts
wiklendt is a jewel in the rough wiklendt is a jewel in the rough wiklendt is a jewel in the rough
Re: grow label height with textbox height....

ok, i found this thread which seems to be the only page on the entire internet which is most closely resembling what i need. however, i still am not sure how to alter my code based on that info. i tried using "Call CtrlMaxHeight(Me)" and "Call CtrlMaxHeight(Me.Name)" but i think i'm doing it wrong...?

i will need the module code to work for several subreports at the same time (one parent report - for now!). i don't know if this changes "index"-ing settings or whether i have to specify anything there...

also, i don't want to have to explicitly name each report in the code. i've tried using some generic code, like Reports(All) etc, though my knowledge in this is limited and have not been able to find anything useful in Help. (i am probably not using the right keywords to get to the help i need... "Reports" is very general a term in the help files!) also, the '.Line' doesn't seem to work when it's preceded with anything other than "Me" (debugger changes the line to red text and says that and equal sing is expected instead of the dash before the "step" keyword...

Plus, if my only option is to explicitly reference the reports, i'm not sure how to keep it to a general "all contols in this report's detail section"...

i can have the module code in the report itself, and it works there, but i would really prefer to have this 'external module'... kind of like when you use cascading style sheets instead of html when you script styling in web pages...

thanks again to anyone who can shed some light on this.
__________________

Agnieszka


Access 2016 x32 | Win10 x64 Home
_________________________________
! a tutorial on
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
wiklendt is offline   Reply With Quote
Old 12-11-2008, 02:47 AM   #5
wiklendt
i recommend chocolate
 
wiklendt's Avatar
 
Join Date: Mar 2008
Location: Cobar, Australia
Posts: 1,746
Thanks: 13
Thanked 20 Times in 18 Posts
wiklendt is a jewel in the rough wiklendt is a jewel in the rough wiklendt is a jewel in the rough
Re: grow label height with textbox height....

oh, i have also tried making the Funciton into a "Public Sub", but that didn't change its dislike for "Me" (no pun intended LOL)
__________________

Agnieszka


Access 2016 x32 | Win10 x64 Home
_________________________________
! a tutorial on
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
wiklendt is offline   Reply With Quote
Old 12-22-2012, 02:16 AM   #6
patatrac
Newly Registered User
 
Join Date: Jan 2010
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
patatrac is on a distinguished road
Re: grow label height with textbox height....

Hi for all
help me please , this code no work for my file,
is possible have an attached exaple file...
thanks
patatrac is offline   Reply With Quote
Old 05-05-2013, 03:28 AM   #7
wiklendt
i recommend chocolate
 
wiklendt's Avatar
 
Join Date: Mar 2008
Location: Cobar, Australia
Posts: 1,746
Thanks: 13
Thanked 20 Times in 18 Posts
wiklendt is a jewel in the rough wiklendt is a jewel in the rough wiklendt is a jewel in the rough
Re: grow label height with textbox height....

patatrac,

I have just gone back and found the database where i was trying to get this to work and am sorry to say i never did manage to get it to work. If you do discover a way, please post your success and details to the thread. Good luck!

Agnieszka.

__________________

Agnieszka


Access 2016 x32 | Win10 x64 Home
_________________________________
! a tutorial on
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
wiklendt is offline   Reply With Quote
Old 05-05-2013, 12:52 PM   #8
ChrisO
Newly Registered User
 
ChrisO's Avatar
 
Join Date: Apr 2003
Location: Brisbane, Australia
Posts: 3,202
Thanks: 7
Thanked 275 Times in 195 Posts
ChrisO is just really nice ChrisO is just really nice ChrisO is just really nice ChrisO is just really nice
Re: grow label height with textbox height....

The equivalent would be…

Behind the Report:-
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    DrawBoxes Me

End Sub
In a standard module:-
Code:
Public Sub DrawBoxes(ByRef rpt As Report)
    Dim intMaxHeight As Integer
    Dim ctl As Control
    Dim lngColourLabel As Long, lngColourText As Long
    
    lngColourLabel = RGB(204, 255, 153)  'pale green
    lngColourText = RGB(236, 236, 236) 'pale grey
    
    'Find tallest control in Detail section
    For Each ctl In rpt.Section(0).Controls
        If ctl.Height > intMaxHeight Then
            intMaxHeight = ctl.Height
        End If
    Next
    
    rpt.DrawStyle = 6 'transparent border, solid fill
    
    'Draw a box around each control in Detail according to its tag property
    For Each ctl In rpt.Section(0).Controls
        If ctl.Tag = "label" Then
            rpt.Line (ctl.Left, ctl.Top)-Step(ctl.Width, intMaxHeight), lngColourLabel, BF
        End If
    
        If ctl.Tag = "text" Then
            rpt.Line (ctl.Left, ctl.Top)-Step(ctl.Width, intMaxHeight), lngColourText, BF
        End If
    Next

End Sub
Hope that helps.


Edit:
And yes, it should be the Detail_Print event.

Chris.

__________________
Access 2003, Win7, GMT +10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by ChrisO; 05-05-2013 at 02:18 PM.
ChrisO is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Make label grow with text box RexesOperator Reports 15 10-13-2008 04:36 PM
fixing Mailing Label height w/ many fields & 'can shrink' dajabo Reports 5 12-17-2004 08:02 AM
Get value from form textbox into report label kallander Modules & VBA 3 08-12-2004 03:23 AM
Trapping textbox height, after its grown llkhoutx Reports 6 11-04-2003 08:16 PM
Fix label height DBL Reports 1 05-01-2002 11:50 PM




All times are GMT -8. The time now is 04:02 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World