Hi Frank,
It looks pretty good. But the crashing may be coming when you try to
hide the WireID group footer within the formatting of it. But I am not sure
on that. Try shifting the code to the WireID group header's On Format event
and get rid of the footer on format subroutine.
To use the numbers it sounds like you already have them joined into the
report's data source query. So all you really should need is to shift to
using them as the grouping items instead of the actual string values. Then
in the the code shift the stuff to use single type values instead of strings.
To help make sure you make all of the changes correctly add this line just
after Option Compare Database:
Option Explicit
This forces the declaration of all variables. So if you mistype one
somewhere, when you compile the code (Debug menu, Compile Database) it will
complain and point out the problem.
Then you can change the two module-level variables at the top:
Private m_sngPreviousDZone As Single
Private m_sngPreviousOZone As Single
Create the new numeric (i.e. OZoneNo, etc.) group header On Format
events and move the code from the string versions to numeric versions,
changing the variables and text box references as needed. Then delete the
old group header format subroutines.
Explanation on the things in my code like "txtWireOriginLocation":
They are actually the names of the text boxes into which Access puts the
values. Usually I rename the text boxes from either the generically
generated name such as Text123 or from their naming by the wizard, that uses
the field name to "txt" followed by the field name. So in code when I see
txtWireOriginLocation I know that it is a text box and that it holds the
contents of the WireOriginLocation field. As an aside check boxes I start
with "chk", buttons with "btn", labels with "lbl" and similar for other
controls. In code you can only, to my knowledge, refer to the text box that
holds a field value, not the actual field.
So, in your case, I am presuming that you used the wizard and that it
named the text boxes with the field names. In which case the code you have
is what you want (not counting the changes to using the numeric values
instead).
If you still run into Access crashing after the change or maybe even
before, try a compact and repair. Make a backup copy first--good to have
regardless. If compacting and repairing does not work, you could try the
decompile/recompile process as documented at
<
http://www.granite.ab.ca/access/decompile.htm>.
Does all that make sense? Let me know if there are questions.
Clifford Bass
FSHOTT said:
When I put the below code in my report and try to get print preview I get a
pop up which says Microsoft Access has encountered a problem and needs to
close. It trys to repair the file and creats a backup. The subsequent reports
cannot be opened in Design View.
I am obviously doing something terribly wrong.
To execute the code below I put in an event procedure in each of the
associated GroupHeaders. Is this the correct procedure?
I also have an additional question. In the below code I am using the string
OZone & Dzone data but also have a related table which convers these to
Single numbers which I can better sort from smallest to largest. I use the
OZoneNo (Origin Zone Number) and DZoneNo in my report to sort the data. How
would I use these fields in the below code instead of the OZone / DZone
strings?
I used the Ozone and Dzone fields in the equations instead of the txtOZone
and txtDZone labels for the controls you recommended. Where should I put
these controls? Currently I use the Ozone & Dzone fields in expressions in
the detail section of the report but do not specifically have the OZone or
DZone as a control to attach the respective labels to. Should I be putting
these sprcific labeled controls in the detail section and making them not
visible?
Here are the actual File Field names in my database.
WireOriginLocation ---> Ozone (String)
WireDestinationLocation ---> Dzone (String)
WireType ---> WireSizeID (String)
HarnessNumber ---> HarnessNo (String)
CODE
Option Compare Database
Private m_strPreviousDZone As String
Private m_strPreviousOZone As String
Private Sub GroupHeaderDZone_Format(Cancel As Integer, FormatCount As Integer)
m_strPreviousDZone = [DZone].Value
End Sub
Private Sub GroupHeaderHarnessNo_Format(Cancel As Integer, FormatCount As
Integer)
m_strPreviousOZone = [OZone].Value
m_strPreviousDZone = [DZone].Value
End Sub
Private Sub GroupHeaderOZone_Format(Cancel As Integer, FormatCount As Integer)
GroupFooterDZone.Visible = ([DZone].Value = m_strPreviousDZone Or
[OZone].Value = m_strPreviousOZone)
m_strPreviousOZone = [OZone].Value
End Sub
Private Sub GroupFooterWireID_Format(Cancel As Integer, FormatCount As
Integer)
Me.GroupFooterWireID.Visible = Len(Nz(Me![Wire ID], vbNullString)) > 0
End Sub