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.....
 
Duane, I tried lebans printlinesVer19.mdb example and I basically get the same thing. I think it has something to do with the SubReports Detail_Format VBA. If I remove that everything works but my image is super tiny then if I add the code then my image is the size needed but then I have spaces. I figured out where to move the text boxes so it didnt cause dbl horizontal lines. Here is what I have, is there any other sugestions for the Detail_Format section? Thanks!

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

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim CtlDetail As Control
Dim intLineMargin As Integer

' This is the spacing between the right edge of the
' control and the Vertical Seperation Line
intLineMargin = 60

' OK lets draw a vertical line to seperate each field
' for each control in details control
' If your last control on the right does not end on the edge of the section
' you will get a second vertical line. If you need to get around this then you
' can skip drawing this last Vertical Seperation Line in a couple of ways.
' We'll use the control name method Here. Our right most control is named
' TestMemo. IF current control is TestMemo - Do not print Vertical Line

For Each CtlDetail In Me.Section(acDetail).Controls
   If CtlDetail.Visible = True Then 'Added
    With CtlDetail
        'If CtlDetail.Name <> "txtHazardAvoidance" Then
        Me.Line ((.Left + .Width + intLineMargin), 0)-(.Left + .Width + _
intLineMargin, Me.Height)
        'End If
    End With 'Added
    End If
Next

        'While we are here lets draw a box around the Detail section
    With Me
        Me.Line (0, 0)-Step(.Width, .Height), 0, B
    End With

Set CtlDetail = Nothing

End Sub

Thanks,
SoggyCashew.....
 
I did some review but wasn't able to get rid of some of the spacing. This is the code I used. Note, I got rid of the DCount() since it shouldn't be necessary with the txtUnboundImagePath in the report.

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    'If DCount("[JobStepID]", "tblJobSteps", "[ImagePath]=""" & txtImagePath & """") > 0 Then
    Me.imgJobStep.Height = 1
    Me.Detail.Height = 1
    If Not IsNull(Me.txtUnboundImagePath) Then
        Me.imgJobStep.Top = 0
        Me.imgJobStep.Height = 1655
    Else
        Me.imgJobStep.Height = 1
        Me.Detail.Height = 1
    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

Duane
Hook'D on Access
MS Access MVP
 
Duane, all these spaces has to do with the image VBA line;

Code:
Me.imgJobStep.Height = 1655

If you drop the size down the gap gets smaller and smaller. I'll keep messing with it but I dont really know what else to try...... Thanks!

Thanks,
SoggyCashew.....
 
I finally got it with no gaps..... Here is the code I used..... :) :) If your courious I can send an example. Thanks a million Duane for sticking it out with me!

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

       Me.Detail.Height = 50
         Me.imgJobStep.Height = 50
          Me.txtJobStep.Height = 50
           Me.txtHazards.Height = 50
            Me.txtHazardAvoidance.Height = 50

    If Not IsNull(Me.txtUnboundImagePath) Then
        Me.imgJobStep.Top = 50
         Me.imgJobStep.Height = 1665
          Me.txtJobStep.Height = 1665
           Me.txtHazards.Height = 1665
            Me.txtHazardAvoidance.Height = 1665
    Else
        Me.Detail.Height = 50
         Me.imgJobStep.Height = 50
          Me.txtJobStep.Height = 50
           Me.txtHazards.Height = 50
            Me.txtHazardAvoidance.Height = 50
    End If
    
End Sub

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

Dim CtlDetail As Control
Dim intLineMargin As Integer

' This is the spacing between the right edge of the control and the Vertical Seperation Line
intLineMargin = 60

' OK lets draw a vertical line to seperate each field
' for each control in details control
' If your last control on the right does not end on the edge of the section
' you will get a second vertical line. If you need to get around this then you
' can skip drawing this last Vertical Seperation Line in a couple of ways.
' We'll use the control name method Here. Our right most control is named
' TestMemo. IF current control is TestMemo - Do not print Vertical Line

For Each CtlDetail In Me.Section(acDetail).Controls
   If CtlDetail.Visible = True Then 'Added
    With CtlDetail
        'If CtlDetail.Name <> "txtHazardAvoidance" Then
        Me.Line ((.Left + .Width + intLineMargin), 0)-(.Left + .Width + _
intLineMargin, Me.Height)
        'End If
    End With 'Added
    End If
Next

        'While we are here lets draw a box around the Detail section
    With Me
        Me.Line (0, 0)-Step(.Width, .Height), 0, B
    End With

Set CtlDetail = Nothing

End Sub

Thanks,
SoggyCashew.....
 
Hi there I found the code posted by oxicottin on the 29th of Feb to do what I wanted with a few adjustments. My only other problem is how do I get the lines to be 1pt wide like I am getting for the header row that I have set up using the properties window since that row does not need to grow. My settings for that row are:
Border Width:1pt
Border Style:Solid

The lines your code draws are thinner. The difference is only noticeable when I print the report.
 
You can use the DrawWidth. Create a new blank report with a detail
section of about 3" in height. Add this code and then preview the
report:
Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
    Dim intY As Integer
    For intY = 1 To 10
        Me.DrawWidth = intY
        Me.Line (0, intY * 50 + 100)-Step(Me.Width, 0)
    Next
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top