Conditional Formatting Continuous Forms

macca the hacke

Macca the Hacca
Local time
Today, 01:08
Joined
Dec 1, 2005
Messages
221
:confused:
Hi. Does anyone know a way to change the colour of controls depending on their value in a continuous form?

I can change the colour of the current row in a continuous form, but I cannot adapt this so that it changes colour depending on the value (ie conditional formatting)

Ta
 
There is no real 'nice' way to do this:

Add a textbox that takes in the entire details-part of your form. Change the textbox's properties to Locked = True, Tabstop = False and add the following code to your form:

The textbox's name in this example is Text1, change it accordingly to your form. Also, change <<SomeOtherControlOnYourForm>> to the name of another control on your form that can get focus.

Code:
Private Sub Text1_GotFocus()
Me.<<SomeOtherControlOnYourForm>>.SetFocus
End Sub

The above code makes sure that the textbox you have made _never_ gets the focus.

If you started off from a blank form, you can now simply add controls on top of the large textbox on your form. If there were allready controls on your form, you won't see them now since the textbox is in the foreground. Simply select it and go into the Format-menu an select "Move to background" or "To background" so that all your other controls float on top of the large textbox.

Finally, it's time to add some conditional formatting to your form. You need to have a counter in your recordsource. You can add a field to your query (that is your recordsource) with the following make-up:

Code:
RunningCount: (SELECT Count(*) 
FROM TABLENAME_1 
WHERE 
[TABLENAME].FIELDNAME1 < [TABLENAME_1].FIELDNAME1
OR 
([TABLENAME].FIELDNAME1 = [TABLENAME_1].FIELDNAME1
AND
[TABLENAME].FIELDNAME2 <= [TABLENAME_1].FIELDNAME2)

In my above example; TABLENAME_1 is the same table as TABLENAME. You can do this by adding the table twice to your query. After you have placed the code and saved your query, you can delete this copy-table (TABLENAME_1). FIELDNAME1 is a date-field and FIELDNAME2 is a unique record-ID.

Add the RunningCount-field to your form and hide it.

In the Format-menu of Access, open the Conditional Formatting function. (I'm not sure of the names since I'm using Access in Dutch ;-) )

- Add two conditions.
- Set them both to "Expression"
- First condition = [RunningCount].[Value]/2=[RunningCount].[Value]\2
- Second condition = [RunningCount].[Value]/2<>[RunningCount].[Value]\2


---

I hope the above makes sense to someone... I'm a very bad teacher and I can't seem to explain something in a sensible way... There was someone who posted an example database that displayed this procedure. It's from him I learned it. Can that person, or anyone who still has the example post it again? It was lost in the form-hijack... :-(

Greetz,

Seth
 
Cheers I will try out and let you know!
 
Could not get to work, but TVM for help. Maybe if someone finds that elusive database.........
 
At last, our prayers have been answered: Office 12 (Office 2006?) features a fantastic setting : "Alternate rowcolor". This would solve your problem if you can wait another year! ;)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom