Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Alternate gray color in continuous form in access 2000

Posted on 2003-11-12
9
Medium Priority
?
595 Views
Last Modified: 2007-12-19
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.

Thanx
0
Comment
Question by:rashida
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 9732534
0
 

Author Comment

by:rashida
ID: 9782310
Pete,

Thanx for the link, I looked at it and it is very confusing is it any esay way to do it?
0
 
LVL 77

Expert Comment

by:peter57r
ID: 9783083
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
else
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.

Pete


0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:rashida
ID: 9812517
Pete,
 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
0
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 total points
ID: 9816143
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.

Pete


0
 

Author Comment

by:rashida
ID: 9844593
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
0
 

Author Comment

by:rashida
ID: 9844612
Pete,
I would like to double the points for you cause it is Thanx giving
0
 
LVL 77

Expert Comment

by:peter57r
ID: 9844842
Conditional Formatiing is found on the Format menu.

Pete
0
 
LVL 5

Expert Comment

by:MitchellVII
ID: 13419080
Hi,

I know this is a closed question, but I've seen many answers given, especially the one at http://www.mvps.org/access/forms/frm0024.htm that just flat out don't work very well and slow things down considerably.  The GetLineNumber Function that gentleman uses at http://www.mvps.org/access/forms/frm0024.htm 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:
CREATING THE ROW COUNTER:
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

ADDING THE ROW COUNTER TO YOUR FORM:
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...)

ADDING THE 'COLOR BAR' TO YOUR CONTINUOUS FORM:
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'.

TO FINISH UP, ADD THE FOLLOWING FORMATCONDITION CODE TO YOUR .OnOpen PROPERTY FOR THE FORM:
Dim objColor As FormatCondition

With Me    
    'Set Format for RowColor:
    ![RowColor].FormatConditions.Delete
    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

OK, THAT'S IT!
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.

Mitchell
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question