?
Solved

Access 2010 VBA Conditional Fromatting

Posted on 2013-06-16
6
Medium Priority
?
467 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 51

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 51

Expert Comment

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

/gustav
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 27

Accepted Solution

by:
MacroShadow earned 1000 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 51

Expert Comment

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

/gustav
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

800 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