Full Version: two similar operations for a single report detail
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
archeomason
I recently requested help in compiling a series of records into a single field with a comma separating the records and was directed to a tutorial website which has pretty much helped out... Here's the link: http://support.microsoft.com/default.aspx?...uct=acc2000#kb2
The general code is as follows:

Sub grpHeaderCategoryID_Format (Cancel As Integer, FormatCount As Integer)

Me!AllProducts = Null
FirstPass = False

End Sub

Followed by:

Sub Detail_Format (Cancel As Integer, FormatCount As Integer)
On Local Error GoTo Detail_Format_Err
If Not FirstPass Then
Me!AllProducts = Me![ProductName]
FirstPass = True
Else
Me!AllProducts = Me!AllProducts & ", " & Me![ProductName]
End If
Detail_Format_End:
Exit Sub
Detail_Format_Err:
MsgBox Error$
Resume Detail_Format_End
End Sub

That has worked great... (with some modifications specific to my db of course...)
I am, however, still stuck... I would like this sub to do a series of three similar operations to produce three separate comma-delineated fields for a single report. I'm sure that this is a basic coding, but how do I essentially run the above operation for one comma-delineated field, then do the same for another source field and destination field on the same report, then repeat that for another source and destination?

Since the tutorial has tied the sub to the ONFormat Event, I'm fairly sure that this all has to be coded in one long string, but am not well-versed enough in the coding to get it to run. I can run it for one field only, more than one and I'm stuck...

Any help would really, really, really be appreciated...
strive4peace
in the future, when you post code, please use

CODE
above your codeblock and


below your codeblock.

This makes it easier for others to read and, therefore, help you
strive4peace
I simplified things a little by assigning an empty string to the control instead of null -- this makes the FirstPass variable unnecessary

CODE
Sub grpHeaderCategoryID_Format(Cancel As Integer, FormatCount As Integer)

   Me.AllProducts = ""
   Me.AllOther1 = ""
   Me.AllOther2 = ""

End Sub

'------------------ Followed by:

Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
   On Local Error GoTo Detail_Format_Err

   If Not IsNull(Me![ProductName]) Then
      Me.AllProducts = Me.AllProducts & ", " & Me![ProductName]
   End If

   If Not IsNull(Me![Other1]) Then
      Me.AllOther1 = Me.AllOther1 & ", " & Me![Other1]
   End If

   If Not IsNull(Me![Other2]) Then
      Me.AllOther2 = Me.AllOther2 & ", " & Me![Other2]
   End If
  
Detail_Format_End:
   Exit Sub

Detail_Format_Err:
   MsgBox Err.Description, , "ERROR " & Err.Number & "  Detail_Format"
   Resume Detail_Format_End

End Sub
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.