Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Changing Font Color Conditional Formatting

Introduction.

With conditional formatting feature of Microsoft Access we can apply up to three colors to the font or background of a Textbox, because only three set of conditions can be set on a field at one time.  If we need more than that then what?  Well, we can do that job ourselves by checking for the specific condition and apply whatever color we want to the font.


The Color Table.

For example, we have a Category Code Combo Box Field on the Form having values range from A to F. When the user selects one of this code from the Combo box the item Description Field’s Font Color should change as per the following color table:

Color Table
Category Color Decimal Hex
A GREEN 32768 #008000
B BLUE 10485760 #000080
C LIGHT BLUE 16711680 #0000FF
D LIGHT GREEN 65280 #00FF00
E RED 128 #800000
F LIGHT RED 255 #FF0000

Design a Form.

Let us try this out on a sample Form.

  1. Open a new Form in Design View.
  2. Click on the Control Wizards button on the Toolbox to enable it.
  3. Select the Combo box Tool and draw a Combo box in the Detail Section of the Form.
  4. Select the Radio Button with the Caption: I will Type in the Values that I want then Click Next.
  5. Type A, B, C, D, E & F in separate rows under Col1 and Click on Finish Command Button.
  6. While the Combo box is still in selected state display the Property Sheet (F4).
  7. Click on the Other Tab of the Property Sheet.
  8. Change the Name Property Value to cboCat.
  9. Select the Event Tab on the Property Sheet.
  10. Select [Event Procedure] from the After Update Event Property.
  11. Click on the Build (. . .) button at the right edge of the After Update Event property to open the VBA Module of the Form.

    Form Module Code.

  12. Copy and paste the following Code overwriting the empty lines of the After Update Event Procedure:
    Private Sub cboCat_AfterUpdate()
    Dim strtxt, num As Integer
    Dim colr As Long
    
    strtxt = Nz(Me![cboCat], "")
    If Len(strtxt) > 0 Then
      num = Asc(strtxt) - 64
    
      colr = Choose(num, 32768, 10485760, 16711680, 65280, 128, 255)
      With Me!Desc
         .ForeColor = colr
      End With
      
    End If
    End Sub
  13. Close the VBA Editing Window to come back to the Form Design.
  14. Create a Textbox to the right of the Combobox.
  15. Display it’s Property Sheet (F4) and select the Other Tab.
  16. Change the Name Property Value to Desc.
  17. Save and Close the Form with the name Sample.

    Try out the Form.

  18. Open the Sample Form in Normal View.
  19. Type your name in the Text box.
  20. Try out our creation by selecting the Category Code (A,B,C,D,E,F) one after the other or in random order and watch the color of your name changes.
Technorati Tags:
Share:

1 comment:

  1. Actually with Access 2010 up to 50 conditions(and hence 50 colours) can be applied at the same time

    ReplyDelete

Comments are subject to moderation before publishing.

Translate



PageRank
Subscribe in a reader
Your email address:

Delivered by FeedBurner

http://clicky.com/101199826
Blog Directory Visit blogadda.com to discover Indian blogs

Search

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Follow by Email

Labels

Forms Functions How Tos MS-Access Security Reports Class Module msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Array Queries msaccess reports External Links msaccess tips Accesstips Downloads Objects Property Collection Object Event Menus and Toolbars Controls MsaccessLinks Process Controls WithEvents Art Work msaccess How Tos Combo Boxes Graph Charts List Boxes VBA msaccessQuery Command Buttons Dictionary Object Form Report Calculation Command Button Data Emails and Alerts Query RaiseEvent Custom Functions Custom Wizards DOS Commands Data Type Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Item msaccessprocess security advanced Access Security Add Auto-Number Field Type Fields Form Instances Key Macros Menus SubForm Top Values Variables msaccess email msaccess menus progressmeter Access2007 Copy Excel Expression Join Methods Microsoft Numbering System Records Recordset Security Split Table Time Difference Utility Workgroup Wrapper Classes database function ms-access msaccess wizards reference text tutorial vba code Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Conditional Formatting Data Filtering Defining Pages Diagram Disk Dynamic Lookup Error Handler Export External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Tables Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif msaccess msaccess alerts pdf files restore switch toolbar updating upload

Featured Post

Running Sum in MS-Access Query

Introduction. We are familiar with creating Auto-Numbers in Query Column, through an earlier Function created with the Name QrySeq(), publi...

Labels

Blog Archive

Recent Posts