Solved

Access 2010 VBA Conditional Fromatting

Posted on 2013-06-16
6
443 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
  • 3
  • 2
6 Comments
 
LVL 49

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 49

Expert Comment

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

/gustav
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 26

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 49

Expert Comment

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

/gustav
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now