I have received your database and now see why you were having problems. You have tried to structure your Detail Section within vertical lines betweeen your controls. If the Detail section grows because the control is set to Can Grow then the formatting of your report looks really bad.
This is what I have done.
1. Modified the Function to string together Serial Numbers and put a counter of the number of Serial Numbers on the front of the string.(i.e. 21-12345, 23456, 33456, etc.) This example tells me in the report that there are 21 serial numbers in the string. I have also included a carriage return left after 12 serial numbers to control where the extra lines start.
2. The query is modified to group by all items and call the serial number function to return this string of serial numbers.
3. The Serial Number control on the report uses the Mid$ function to strip off the "21-" at the beginning of the string.
4. Created an additional control with the entire string in it but made it invisible so that through code I could pick up the value 21 from the front of the string.
5. In the Detail section OnFormat event procedure I used the number of serial numbers to determine the height that was necessary for the Detail Section and the vertical lines to accommodate the number of extra rows that would be displayed in the Serial Number control as it grew due to the large string being returned.
Function Code:
Code:
Public Function SerialString(vID As String)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim vSerialString As String, vCount As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_SN", dbOpenDynaset)
rs.FindFirst "[NSN] = '" & vID & "'"
Do
If Not rs.NoMatch Then
vSerialString = vSerialString & rs("SERIAL_NUM") & ","
vCount = vCount + 1
If vCount Mod 12 = 0 Then
vSerialString = vSerialString & vbCrLf
End If
End If
rs.FindNext "[NSN] = '" & vID & "'"
Loop Until rs.EOF Or rs.NoMatch
SerialString = IIf(Not IsNull(vSerialString), vCount & "-" & Left(vSerialString, Len(vSerialString) - 1), "No Matching Serial Numbers")
rs.Close
db.Close
End Function
Detail Section OnFormat Event Procedure:
Code:
Dim x As Integer
x = Mid$([SNString], 1, InStr(1, [SNString], "-") - 1)
If Reports!rptBob_Example.Section(0).Height < 500 Then
Reports!rptBob_Example.Section(0).Height = 480 + (Fix(x / 12) + IIf(x Mod 12 > 0, 1, 0)) * 90
Me![Line75].Height = Reports!rptBob_Example.Section(0).Height
Me![Line79].Height = Reports!rptBob_Example.Section(0).Height
Me![Line80].Height = Reports!rptBob_Example.Section(0).Height
Me![Line81].Height = Reports!rptBob_Example.Section(0).Height
Me![Line82].Height = Reports!rptBob_Example.Section(0).Height
Me![Line83].Height = Reports!rptBob_Example.Section(0).Height
Me![Line84].Height = Reports!rptBob_Example.Section(0).Height
Me![Line85].Height = Reports!rptBob_Example.Section(0).Height
Me![Line86].Height = Reports!rptBob_Example.Section(0).Height
Me![Line87].Height = Reports!rptBob_Example.Section(0).Height
Me![Line88].Height = Reports!rptBob_Example.Section(0).Height
Me![Line89].Height = Reports!rptBob_Example.Section(0).Height
Me![Line76].Height = Reports!rptBob_Example.Section(0).Height
End If
These modification will all for varying number of lines in a single control as it grows and shrinks. The detail section and its vertical lines will shrink and grow with it.
Good luck with your project.
Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]