How do I green band in a Form

G

Guest

Green banding is the application of a background colour (yes, the proper
English spelling) to a row of data to make it easier to see on a report and
I would like to do the same on a form when veiwed on a screen.

I have been very comfortable with doing "green banding" in reports but have
an issue to do so in a form. I can't see how to apply such a band to a
"detail" line of a form when presented on screen. The "green band" for
reports is done using the "on format" property as below. But there is no "on
format" property on the properties of a "detail" section of form.

How can I do a green band on a form?

Example Greenband for reports
(Explicit declaration)
Dim greenbar As Boolean

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If greenbar Then
Detail.BackColor = 12181965 'a nice shade of pale green that prints well
Else
Detail.BackColor = vbWhite ' forced to resort to American spelling !
End If
greenbar = Not (greenbar)
End Sub
 
F

fredg

Green banding is the application of a background colour (yes, the proper
English spelling) to a row of data to make it easier to see on a report and
I would like to do the same on a form when veiwed on a screen.

I have been very comfortable with doing "green banding" in reports but have
an issue to do so in a form. I can't see how to apply such a band to a
"detail" line of a form when presented on screen. The "green band" for
reports is done using the "on format" property as below. But there is no "on
format" property on the properties of a "detail" section of form.

How can I do a green band on a form?

Example Greenband for reports
(Explicit declaration)
Dim greenbar As Boolean

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If greenbar Then
Detail.BackColor = 12181965 'a nice shade of pale green that prints well
Else
Detail.BackColor = vbWhite ' forced to resort to American spelling !
End If
greenbar = Not (greenbar)
End Sub

Won't work on a form.

Access 2002 or newer?
See
http://www.lebans.com
specifically:
http://www.lebans.com/conditionalformatting.htm
You can down load a sample database that includes various uses for
shaded lines, including continuous form alternating lines and
highlighting the selected line.

And also look at:
http://www.lebans.com/alternatecolordetailsection.htm
 
R

Rob Parker

Hi Rob,

Here's how I do it; it involves a little trickery with a couple of textbox
controls, conditional formatting, and a custom function.

Add a textbox (tboxRowColour) to the detail section of the form; make it
large enough to cover the entire row, and Send To Back.

Add another textbox (tboxRowNum) in the detail section; set its visible
property to No; set its Control Source to:
=GetLineNumber([Form],"RecordID",[RecordID])
where RecordID is the name of a unique field in your recordset (I normally
use the primary key field (generally an autonumber))

Add the following code in a standard module:

Function GetLineNumber(f As Form, KeyName As String, KeyValue) As Integer
Dim rs As DAO.Recordset
Set rs = f.RecordsetClone
' Find the current record.
rs.FindFirst "[" & KeyName & "] = " & KeyValue
GetLineNumber = rs.AbsolutePosition
End Function

Set the Back Style of all the existing controls to Transparent.

Set up Conditional Formatting for tboxRowColour as follows:
In the Default Formatting sectio, set the background colour to the
standard colour.
In Condition 1, select Expression Is, enter "[tboxRowNum] Mod 2" as the
expression, and set the background colour to the green-band colour.

And that's it! The green-band formatting will be lost for any control which
has focus (ie. when you click in a textbox); and the green-banding will not
appear if you scroll by click-dragging the vertical scroll bar until it is
released.

HTH,

Rob (Melbourne, Oz)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top