Solved

Access 2010 VBA Conditional Fromatting

Posted on 2013-06-16
6
462 Views
Last Modified: 2013-06-17
Hi,

I know that since the access 2010 u have the ability to create 50 conditional formatting rules, but i would like to  create them dynamicly. Because the user can has the ability to create new rules (rules based on a reminder type). this way the user does not need to  conctact us when their is a new reminder type.

It seems possible to create the rules by vba, but their's one problem, when i create the fourth Formatrule, access just override the first 1 again, after creating all the format rules, we just keep the last 3 over.

Via the GUI is it possible to create the 3+ formattingrules.

Function setConditionalFormats()
Dim vControl As control
Dim vTextbox As TextBox
Dim sql As String
Dim rst As New adodb.Recordset
Dim teller As Integer

    Call OpenConnections
    For Each vControl In Me.Controls
        If TypeName(vControl) = "Textbox" Then
            teller = 0
            Set vTextbox = vControl
            sql = "select alarmsoort, weergave_kleur from alarmsoort"
            rst.Open sql, G_SQLConn, adOpenForwardOnly, adLockReadOnly
            Do Until rst.EOF
                vTextbox.FormatConditions.Add acExpression, , "[Alarmsoort] = " & rst!Alarmsoort
                vTextbox.FormatConditions(teller).ForeColor = rst!weergave_kleur
                teller = teller + 1
                rst.MoveNext
            Loop
            rst.Close
        End If
    Next
    
End Function

Open in new window


this function should create for every textbox on this subform the conditional formats based on the "Alarmsoort" Table.
0
Comment
Question by:Jorosoft_bvba
[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
  • 3
  • 2
6 Comments
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 39252318
It seems as if the limit still is three.
Also, be aware that setting of FC may slow down the form or make it flickering.

Further, I would turn your loop round to open the recordset once, then - for each record - loop the TextBox controls and set the FCs.

/gustav
0
 

Author Comment

by:Jorosoft_bvba
ID: 39252341
Hi Gustav,

Indeed i should better switch my loops, but that aside.

Like u say, it seems a limit via the vba, but i think it's strange u can add 50 FC's by GUI, but by VBA code ur limited to 3 FC's. It seems like a upside down world, so i couldnt believe it first and maybe someone knows a work around.

Grtz,
Jorosoft
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 39252355
Yes, it is weird. Let's see if some explanation will be brought forward.

/gustav
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 27

Accepted Solution

by:
MacroShadow earned 250 total points
ID: 39252371
0
 

Author Comment

by:Jorosoft_bvba
ID: 39252410
MacroShadow,

this dit the trick. Not the CF i expected, but this does what i need.

rivate Sub Detail_Paint()
  Select Case Me.Fieldname.Value
  Case 1:
    Me.Fieldname.Backcolor = RGB (0, 0, 0)
    Me.Fieldname.FontBold = True
  Case 2:
    Me.Fieldname.Backcolor = RGB (0, 255, 0)
  Case 3:
    Me.Fieldname.Backcolor = RGB (0, 0, 255)
...............
  Case 9999999999:
    Me.Fieldname.Backcolor = RGB (255, 255, 255)
    Me.Fieldname.Whatever = Whatever 'the main advantage of self-made CF
  End Select
End Sub

Open in new window


Thx,
Jorosoft.
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 39252455
Just have in mind, it won't work in datasheetview.

/gustav
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

690 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