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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically sizing a grid on an ACCESS report 1

Status
Not open for further replies.

RDS2

Technical User
Jun 6, 2003
44
US
I want my data laid-out in grid (very much like an Excel row) on a report. Is there a native way in ACCESS to size the grid row to the tallest field memeber of that row?
 
RDS2,
Does the [tt]CanGrow[/tt] propery of the controls in the detail section do what you want?

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Thanks for the response.

You could "grow" the section and its related fields but there is no "can grow" property for the lines or rectangle that create the grid. You would end up with differing height boxes rather than all "boxes" that comprise the grid being of equal height. One possible soution is to code the format event using the LINES method. This is what I'm trying to avoid if possible.
 
If you have all your controls touch then you can make the border solid and thereby making a grid around them.

I am guessing if you set the can grow property to true, you could then find the control with the greatest height and then set all of them to that height. This should in effect resize everything. Of course you will need to turn on can shrink as well.

I believe a section has a controls collection so you should be able to step through the collection and only perform you logic based on one or more control types (I am thinking select case statment).

If it works this method should be much easier to deal with. If butting the controls next to each other doesn't work you could still apply the same control section logic to your lines... Just set the height to the section height.

You seemed to know what you were doing when you said use the format event. I hope this is enough. If you get it working, I am sure others will be interested in the code. It may even be FAQ worthy.
 
Both,
I was thinking something along the same lines, and yes the [tt]Detail[/tt] section does have a [tt]Controls[/tt] collection.

I played around a little with both ideas and I'm pretty sure you will need to monkey with the [tt]MoveLayout()[/tt] and [tt]NextRecord()[/tt] properties. I didn't and managed to get everything sized correctly, BUT each control was on a different line.

If you decide to go this route and encounter problems post back and we can do what we can to help.

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
CautionMP,

Couldn't you get away with just setting the Top property of the controls as well?
 
You need to find the tallest control in the On Print event of the detail section. Then draw a rectangle around each control. This method requires the Border property be transparent since the "borders" are drawn using the Line Method of the report.

Select all the controls you want to "grow" and enter [red]Border[/b] in their tag properties. Then add this code to the On Print event of the detail section:
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 all controls 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), , B
        End If
    Next
End Sub

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks to all that have responded. I guess the key here is to determine the tallest control and then (programmatically)set all other controls on that line to the same height.
Thanks Duane.
 
Actually [red]"then (programmatically)set all other controls on that line to the same height"[/red] isn't quite true. You can only find the height of the tallest control in the On Print event. You can't control the height of any control in the On Print event. That is why the code uses the Line method to draw the borders.


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
dhookom

Thanks for your valuable post! Your code works flawlessly and achieves exactly the result I was looking for.

RDS2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top