Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

background color of a table row

Status
Not open for further replies.

ANDYM

Programmer
Jul 6, 2000
15
0
0
GB
On a continuous form, if you select a field in an given row, is there a way you can set the backcolour of that row to a different colour than the other rows.<br>
 
Perhaps this would help...it's a thread from a few days back, but is useable...(damn, too late for spelling today) for forms.&nbsp;&nbsp;If you aren't using a datasheet, but rather a continuous form, there might be an application.<br><br>HTH, and Thank you Tasmin for the code ;)<br>Drew<br><br>TASY (TechnicalUser) Jul 4, 2000 <br>Hi all<br><br>I have created a report, with lots and lots of fields, most of which have a value of zero. Is there any way to make the fields that are NOT zero bold?? It would make them stand out a little nicer.<br><br>Thanks! <br>Tasmin Zimak&nbsp;&nbsp;<br><br>TASY (TechnicalUser) Jul 5, 2000 <br>Well, I answered my own question!!<br><br>I wrote some code, which is at the end of this post, and attached it to the &quot;On Print&quot; event of the detail section of the report. <br><br><br>Dim text1 As Control, text2 As Control, text3 As Control, text4 As Control, text5 As Control<br><br>Set text1 = Me!SUSSEPT<br>Set text2 = Me!SUSOCT<br>Set text3 = Me!SUSNOV<br>Set text4 = Me!SUSDEC<br>Set text5 = Me!SUSJAN<br><br>If (Val(text1.Text) &lt;&gt; 0) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;text1.FontBold = True<br>Else<br>&nbsp;&nbsp;&nbsp;&nbsp;text1.FontBold = False<br>End If<br><br>Tasmin Zimak<br><A HREF="mailto:tzimak@board.ugdsb.on.ca">tzimak@board.ugdsb.on.ca</A><br><br>DreewToo (Programmer) Jul 5, 2000 <br>Do you think the same techinique could be used to change the color of a font conditionally on a form?<br><br>Drew&nbsp;&nbsp;<br><br>TASY (TechnicalUser) Jul 5, 2000 <br><br>Yes it can. Use it with the &quot;On Load&quot; event of the form. The property to change the colour is &quot;ForeColor&quot;. Other ones are &quot;FontSize&quot;, &quot;FontItalic&quot; and &quot;FontName&quot;.<br><br><br>Tasmin Zimak<br><A HREF="mailto:tzimak@board.ugdsb.on.ca">tzimak@board.ugdsb.on.ca</A><br>&nbsp;<br>&nbsp;<br>
 
The information in the above post is for a report, in which you CAN change row colors based on criteria.<br><br>You can also change the colors of fields in a single form. <br><br>However, you CAN'T change field colors on a continuous form for an individual row, as it will change it for every row (or record). It makes no difference if you change the colors manually (through the properties window) or in code, cause it simply repeats the same instruction for every row. <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
I hadn't realized that.&nbsp;&nbsp;Thank you for correcting my misinformation.<br><br>Drew
 
Thanks Dirk, however, I don't know if that will do what we are looking for. I haven't had time to really look at it, but it looks like it just highlights the selected row (the title was &quot;Changing the Background Color of the <b>Current Record</b> in a Continuous Form&quot;. A couple of these posts were asking for conditional stuff and highlighting various rows. <br><br>I will have to look at it closer when I get some time. I do know however, that Dev is a pretty sharp guy, and he has some great ideas, so it may very well work. <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
ACCESS 2000 has &quot;Conditional Formatting&quot; which allows formatting in ANY form view, including Datasheets!

Just highlight the control you want to change, then FORMAT, CONDITIONAL FORMATTING... you can set the conditions and what type of formatting you want.

Even better, you can then use the COPY FORMAT button (the icon with the 'paintbrush' next to PASTE, to copy the 'conditional formating' from one cell to another.

Try it! It will make you happy.
 
Kerock points out a little known but very useful fact, however don't confuse CONDITIONAL formatting with POSITIONAL formatting, which is what the original poster wants to do - highlighting the CURRENT record, REGARDLESS of its' data.

Other than the semi-solution on Dev's site, there is no way to HIGHLIGHT an entire ROW in a continuous form, and not have ALL the rows highlight. It's just the way a continuous form is built.

I am working on a utility however, to &quot;fake&quot; it as best as can be done, and it seems to be working. It takes a little up front work, but it is as close as anything I've ever seen. Stay on this thread for updates.

Jim
How many of you believe in telekinesis? Raise my hand...
Another free Access forum:
More Access stuff at
 
One way to do this (In Access 2000 of course) is to add a boolean field to the table that the form is based on and set it's Default value to False. Lets call the field &quot;Hilight&quot;. Add this field to the form and set it's Visible property False.

Set the Conditional Formatting for each field on the form as follows:

From the drop-down list select &quot;Expression Is&quot; and in the second box type [Hilight]=True. Set the background colour you want the current record to have. You could also change the font colour, make the font bold, italic and so on.

In the Current event of the form add code that loops through all the records and sets the Hilight field to False.

Private Sub Form_Current()

Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset

rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic

'You may want to apply a filter if the table is large

rst.Open &quot;Select Hilight From Customers&quot;

If Not (rst.BOF And rst.EOF) Then
Do While Not rst.EOF
rst![Hilight] = False
rst.Update
rst.MoveNext
Loop
End If

rst.Close
Set rst = Nothing

'Set the Hilight field for the current record to true

Me.Hilight = True

End Sub

Now as you move to a record on the form the background colour will change. It's not pretty and it may not not be the best solution if the form displays a very large number of records but it works very well for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top