Solved

Access 2010 VBA Conditional Fromatting

Posted on 2013-06-16
6
451 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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 49

Expert Comment

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

/gustav
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

777 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