I have been attempting to shade a control in a report when the highest value in a query field is shown. I received some assistance in the form of code suggestion as follows:
Option Compare Database
Option Explicit
'Global declaration to hold the max value
Dim lngMax As Long
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'This will be run everytime a record in the detail section
'is rendered on the report. You can use it to change the
'formatting of the detail, a field, text...
If Me.lngRecord = lngMax Then 'Check the record data
'Make the control BackColor grey because I am the
'the max value
Me.Controls("lngRecord").BackColor = 12632256
Else
'Reset the BackColor to the default because I don't
'match
Me.Controls("lngRecord").BackColor = 16777215
End If
End Sub
Private Sub Report_Open(Cancel As Integer)
'Use the DMax() function to find the max value
lngMax = DMax("lngRecord", "tblColumnWrap")
End Sub
I cant seem to get the backcolor to change and I think it is the dmax function. when i set the lngrecord=lngmax, none of the fields shade, but if I set lngrecord >lngmax, they all do. I am not sure why this wont work as suggested, but willing to try again. All good advice appreciated.
Option Compare Database
Option Explicit
'Global declaration to hold the max value
Dim lngMax As Long
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'This will be run everytime a record in the detail section
'is rendered on the report. You can use it to change the
'formatting of the detail, a field, text...
If Me.lngRecord = lngMax Then 'Check the record data
'Make the control BackColor grey because I am the
'the max value
Me.Controls("lngRecord").BackColor = 12632256
Else
'Reset the BackColor to the default because I don't
'match
Me.Controls("lngRecord").BackColor = 16777215
End If
End Sub
Private Sub Report_Open(Cancel As Integer)
'Use the DMax() function to find the max value
lngMax = DMax("lngRecord", "tblColumnWrap")
End Sub
I cant seem to get the backcolor to change and I think it is the dmax function. when i set the lngrecord=lngmax, none of the fields shade, but if I set lngrecord >lngmax, they all do. I am not sure why this wont work as suggested, but willing to try again. All good advice appreciated.