Alternate gray color in continuous form in access 2000

I'm trying to create a sub form in access 2000 and I would like to show alternate gray lines (just like we can see on web). Please advice.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rashidaAuthor Commented:

Thanx for the link, I looked at it and it is very confusing is it any esay way to do it?
There is no easy way unless you happen to have a sequentially numbered field running though the query or table that your continuous form is based on (such as an autonumber).
If you have such a field then you can use conditional formatting to format a texbox based on the value of the sequential field.  If you don't have then the example I directed you to is really the only way.

If you have a field available then you do something like:

if me.myfield mod 2 = 0 then
me.texbox.backcolor =vbred
me.texbox.backcolor = vbblue
end if

where textbox is a texbox that you've sized to cover the whole record.

It's much easier in reports.


The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

rashidaAuthor Commented:
 Here is the situation, I created a field in a table as autonum and called it ID and then I created two fields  in a continuous form and they are with their name and control source

- first field is ID (sequentially numbered )
 - Name is RowNum with control source ID (which gives me autonum from the table)
- second field is (non sequentially numbered)
 - Name is RowNum2 and control source =[RowNum]*-1

then I had the code you suggested on the current event of the form.

It did not work. Where did I miss the link
If you now have an autonumber field in the form then use conditional formatting.  
Draw a textbox to cover the size of the form, send it to the back and use conditional formatting so that if the autonum field is odd then it's one colour else it's a different colour.

You can test for odd and even as I indicated before:
If the expression:
myfield mod 2 = 0  
then myfield  is even.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rashidaAuthor Commented:
Thanx again, I created a text box as you said and send it back, but I could not find the conditional formatting to put the expression.  Please advise
rashidaAuthor Commented:
I would like to double the points for you cause it is Thanx giving
Conditional Formatiing is found on the Format menu.


I know this is a closed question, but I've seen many answers given, especially the one at that just flat out don't work very well and slow things down considerably.  The GetLineNumber Function that gentleman uses at works but it seems like using an atom bomb to blow up and ant.

Here is the solution I use in my database for ALTERNATING ROW COLORS.  It's fast, accurate and loads/updates almost instantly with very little screen flicker.  I credit 'bobonline' with the Row Counter part of this.

Actually using FormatCondition to create the row color change is the easy part.  The hard part seems to have been generating the Row Numbers without using code that has to cycle through a .RecordsetClone or use something like DCount to do it.

Ok, here it is anyway:
Just create a new Module and paste this into it:

Public Function Row_Number(vForm As Form) As Long
Static I As Integer

'Add Row Numbers to Continuous Forms:
I = I + 1
Row_Number = I
End Function

Add an unbound Text Control to your form called "RowNum".  Set the .ControlSource of 'RowNum' to '=Row_Number([Form])'.  Ok, now you have your speedy row counter. (Thanks bobonline - I know you said this might be buggy, but it's never created a single error message for me...)

Just create a Unbound TextBox Control that spans the height and width of your continuous form detail section.  Name the Control 'RowColor'.  Make it's .backcolor vbWhite or any color you prefer as a default.  Send your new RowColor control to the back of the form in design mode.  Now set the .backcolor for all the controls on top of 'RowColor' to whatever color you wish to appear when you click the control, then set them all to 'Transparent'.

Dim objColor As FormatCondition

With Me    
    'Set Format for RowColor:
    Set objColor = ![RowColor].FormatConditions.Add(acExpression, , "[RowNum] mod 2 <> 0")
    With ![RowColor].FormatConditions(0)
        .BackColor = COLOR_GRAY_LT (Use whatever Color Code you want your alternating Row to be here -I like light gray, but you may like whatever...)
    End With
    Set objColor = Nothing
End With

Just open your form now and alternating colors load zippity zap, no screen flash (to speak of).  Very clean.

Maybe there is some bug in here that won't work in some situations, but I have a Main form with 6 relatively complex subforms on it and they all load perfectly and fast using this.  When I tried this same formatting using GetLineNumber() it was slow and a mess.  Sometimes it would give me 3 rows in a row all same color, etc...not good.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.