Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access 2010 VBA Conditional Fromatting

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

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 52

Expert Comment

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

/gustav
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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 52

Expert Comment

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

/gustav
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

610 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