Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize controls based on largest text box

Status
Not open for further replies.

oxicottin

Programmer
Jun 20, 2008
353
US
Hello, I have a report (rptVVWI) with a subreport (rptVWISubreport) and in the subreport there are 4 controls, the last being an image.

1)txtJobStep
2)txtHazards
3)txtHazardAvoidance
4)imgJobStep

Right now I have it to where I limit the amount of text by 300 caracters and it fits in the code im using in the Subreports Detail OnFormat event but I dont want to restrict the amount of text I can have so how can I,

1) Have the largest control out of txtJobStep, txtHazards, txtHazardAvoidance decide the height of all the controlls for that record/row OR if those controls are no bigger than Height = 1570 then set that record/row to that height. Below is the code im using as of now. Thanks!

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
     Me.imgJobStep.Height = 1470
     Me.txtHazardAvoidance.Height = 1570
     Me.txtHazards.Height = 1570
     Me.txtJobStep.Height = 1570
     Me.imgJobStep.Top = Me.txtHazardAvoidance.Top + 50
End Sub

Thanks,
SoggyCashew.....
 
You can't grab the height of "Can Grow" controls until the On Print event. At that point, it is too late to set the height (or other size) properties of the controls.

What is your bottom line reason for doing this? Are you worried about the borders looking out of alignment? If this is your real issue then you can find the tallest control and use the Line Method to draw lines around controls. This assumes you have removed the borders from the controls.

Duane
Hook'D on Access
MS Access MVP
 
Yes all four controls have borders and yes that would be a very good reason. They all got to line up all the way across. If I removed the borders how can I use this line method your talking about. But I still don't want it to go over 1570 if those controls are no bigger than that height. Thanks!

Thanks,
SoggyCashew.....
 
Ok, I did a search and found the code below.
Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim intMaxHeight As Integer
Dim ctl As Control
'Find highest control in Detail section _
that has a tag property of "Border"
For Each ctl In Me.Section(0).Controls
If ctl.Tag = "Border" Then
If ctl.Height > intMaxHeight Then
intMaxHeight = ctl.Height
End If
End If
Next
'Draw a box around each control in Detail _
that has a tag property of "Border"
For Each ctl In Me.Section(0).Controls
If ctl.Tag = "Border" Then
Me.Line (ctl.Left, ctl.Top)- _
Step(ctl.Width, intMaxHeight), vbBlack, B
End If
Next

End Sub

It changes the size to the largest text box but the borders look like the image below.

With code from above...

With origional code and the way I need it to look....



Thanks,
SoggyCashew.....
 
Yes it is yours :) .... the controls borders are set to transparent.



Thanks,
SoggyCashew.....
 
They were white I set to transparent and now the lines show as they should :). Now for the second part of my question. I have a hidden text box in the background called (txtImagePath) that gives the path of the image that is in the visible image box called (imgJobStep) so if there is an image for that record I wanted the image to be .Height = 1570 can I do something like:

Code:
If DCount("[JobStepID]", "tblJobSteps", "[ImagePath]=""" & txtImagePath & """") > 0 Then

or what could I do? Thanks!

Thanks,
SoggyCashew.....
 
Ok, I think Im not explaining this correctly. In this image;
it shows two images in rows 1 and 2 and the entire row is that size (1570) and outlined "Besides the image". Then in row 3 and 4 there is no image but the row is still (1570). What I wanted was if there is no image for a row using;

Code:
If DCount("[JobStepID]", "tblJobSteps", "[ImagePath]=""" & txtImagePath & """") > 0 Then

Then have that row the size of the largest text field and if there is an image then have it 1570 UNLESS there is a text field that is larger then have it that size and the image still would be 1570. I hpe Im explaing this better. I did however try the On Format event using the code below but what it did was made every row 1570 and outlined the text boxes to the highest one even if it was smaller than the image so there was gaps everywhere. Thanks!

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If DCount("[JobStepID]", "tblJobSteps", "[ImagePath]=""" & txtImagePath & """") > 0 Then
        Me.imgJobStep.Top = 0
        Me.imgJobStep.Height = 1570
    Else
        Me.imgJobStep.Height = 0
        Me.Detail.Height = 0
    End If

End Sub

Thanks,
SoggyCashew.....
 
I believe you would need to set the detail section height back down to the smaller height after setting the image height. BTW: I can't view your image from a work laptop since the domain is blocked.

Duane
Hook'D on Access
MS Access MVP
 
Duane, im still trying to figure it out and I cant get anything to work. I tried your sugestion and if there is an image then every record is the 1470. Im doing something wrong....

Thanks,
SoggyCashew.....
 
Its the same as above I just dont see why it doesnt work. What I think its doing is the report is continious so if the first record has an image it sets all the records to 1570 but then it outlines all the text boxes to the height of the tallest control for each record. I need it to if the record has an image then it sizes the image to 1570 and the controls outlines to that size as well but if the text is larger than the image it sizes it to the largest control and if there is no image then it just sizes to the largest control. I have a hidden control in the detail section that gives a image path if there is an image and is blank or no is is avalable for that record. Im using the DCount to find that but im not doing something right obviously. This is out of my skill knowledge.

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If DCount("[JobStepID]", "tblJobSteps", "[ImagePath]=""" & txtImagePath & """") > 0 Then
        Me.imgJobStep.Top = 0
        Me.imgJobStep.Height = 1570
    Else
        Me.imgJobStep.Height = 0
        Me.Detail.Height = 0
    End If

End Sub

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
     Dim intMaxHeight As Integer
     Dim ctl As Control

For Each ctl In Me.Section(0).Controls
If ctl.Tag = "Border" Then
If DCount("[JobStepID]", "tblJobSteps", "[ImagePath]=""" & txtImagePath & """") > 0 Then
If ctl.Height > intMaxHeight Then
intMaxHeight = ctl.Height
  End If
 End If
 End If
Next
'Draw a box around each control in Detail
'that has a tag property of "Border"
For Each ctl In Me.Section(0).Controls
If ctl.Tag = "Border" Then
Me.Line (ctl.Left, ctl.Top)- _
Step(ctl.Width, intMaxHeight), vbBlack, B
End If
Next



End Sub

Thanks,
SoggyCashew.....
 
Do you know which lines of code are being run? I would limit the report to two records, one with an image and another without. Then try code like:
Code:
CODE
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If DCount("[JobStepID]", "tblJobSteps", "[ImagePath]=""" & txtImagePath & """") > 0 Then
        Me.imgJobStep.Top = 0
        Me.imgJobStep.Height = 1570
        Debug.Print "Dcount()>0"
    Else
        Me.imgJobStep.Height = 0
        Me.Detail.Height = 0
        Debug.Print "Dcount()=0"
    End If
End Sub
See what happens.
Are there really no other controls in the detail section so you can set the height to 0? How about try setting the height to something other than 0?

Duane
Hook'D on Access
MS Access MVP
 
Duane, Would it be alright if I upload the DB to my dropbox or somewhere perfered so you could have a look at it? I would have to cut it down due to its size so it might take a day or so.

Thanks,
Chad

Thanks,
SoggyCashew.....
 
duane, by adding the code you posted (Debug.Print "Dcount()>0") it now does what I was looking for BUT between/below SOME records there is a space and it could be large or small. I can post an image but not sure what your work allows. here is the full code thats in my report.

Code:
Option Compare Database
Option Explicit

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If DCount("[JobStepID]", "tblJobSteps", "[ImagePath]=""" & txtImagePath & """") > 0 Then
        Me.imgJobStep.Top = 0
        Me.imgJobStep.Height = 1570
        Debug.Print "Dcount()>0"
    Else
        Me.imgJobStep.Height = 0
        Me.Detail.Height = 0
        Debug.Print "Dcount()=0"
    End If
End Sub

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
 Dim intMaxHeight As Integer
     Dim ctl As Control

For Each ctl In Me.Section(0).Controls
If ctl.Tag = "Border" Then
If ctl.Height > intMaxHeight Then
intMaxHeight = ctl.Height
  End If
 End If
Next
'Draw a box around each control in Detail
'that has a tag property of "Border"
For Each ctl In Me.Section(0).Controls
If ctl.Tag = "Border" Then
Me.Line (ctl.Left, ctl.Top)- _
Step(ctl.Width, intMaxHeight), vbBlack, B
End If
Next
End Sub

Thanks,
SoggyCashew.....
 
Ok Duane, I changed the background color of the controls and they were correct (Image Gaps_1) and then I changed the background color of the detail section
to red and its alternate background color to yellow and I got what in (Image Gaps_3). And in image 2 its the origional no color/transparent.


1)
2)
3)

Thanks,
SoggyCashew.....
 
Ok, I found something interesting. the more lines of text I have the bigger the gap is so if the text fits on the first row then I dont have a gap but if It runs onto the second row then there is a small gap and then if it run onto the third row then the gap is larger. Am I missing a setting?

Thanks,
SoggyCashew.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top