473,383 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Is it Possible to Cycle Through Properties of a FormatCondition?

twinnyfo
3,653 Expert Mod 2GB
Friends,

This might be relatively easy, or relatively impossible.

I am trying to find all the Text Boxes and Combo Boxes that have conditionial formatting applied to them. That, in itself, is easy enough.

However, there appears to be no way to simply run through the list of Conditional Formatting properties. For example, when I cycle through properties for a Control, the language might be:

Expand|Select|Wrap|Line Numbers
  1. For Each prp in ctl.Properties
  2.     'Do what you wish here
  3. Next prp
But with Conditional Formatting, it appears this is the only way to work through it:

Expand|Select|Wrap|Line Numbers
  1. Public Sub FindCF()
  2.     Dim db          As DAO.Database
  3.     Dim appAccess   As Access.Application
  4.     Dim frm         As Object
  5.     Dim frmObj      As Access.Form
  6.     Dim ctl         As Control
  7.     Dim objTB       As TextBox
  8.     Dim fc          As FormatCondition
  9.  
  10.     Set db = CurrentDb()
  11.     Set appAccess = Access.Application
  12.     For Each frm In db.Containers("Forms").Documents
  13.         With appAccess.DoCmd
  14.             Call .OpenForm(FormName:=frm.Name, _
  15.                            View:=acDesign)
  16.         End With
  17.         Set frmObj = appAccess.Forms(frm.Name)
  18.         For Each ctl In frmObj.Controls
  19.             If ctl.ControlType = 109 Then
  20.                 Set objTB = ctl
  21.                 If Not objTB.FormatConditions.Count = 0 Then
  22.                     Debug.Print "Control Name: " & ctl.Name
  23.                     For Each fc In objTB.FormatConditions
  24.                         Debug.Print "BackColor: " & fc.BackColor
  25.                         Debug.Print "Enabled: " & fc.Enabled
  26.                         Debug.Print "Expression1: " & fc.Expression1
  27.                         Debug.Print "Expression2: " & fc.Expression2
  28.                         Debug.Print "FontBold: " & fc.FontBold
  29.                         Debug.Print "FontItalic: " & fc.FontItalic
  30.                         Debug.Print "FontUnderline: " & fc.FontUnderline
  31.                         Debug.Print "ForeColor: " & fc.ForeColor
  32.                         Debug.Print "LongestBarLimit: " & fc.LongestBarLimit
  33.                         Debug.Print "LongestBarValue: " & fc.LongestBarValue
  34.                         Debug.Print "Operator: " & fc.Operator
  35.                         Debug.Print "ShortestBarLimit: " & fc.ShortestBarLimit
  36.                         Debug.Print "ShortestBarValue: " & fc.ShortestBarValue
  37.                         Debug.Print "ShowBarOnly: " & fc.ShowBarOnly
  38.                         Debug.Print "Type: " & fc.Type
  39.                     Next fc
  40.                 End If
  41.                 Set objTB = Nothing
  42.             End If
  43.         Next ctl
  44.         With appAccess.DoCmd
  45.             Call .Close(ObjectType:=acForm, _
  46.                         ObjectName:=frm.Name, _
  47.                         Save:=acSaveNo)
  48.         End With
  49.     Next frm
  50.     Set appAccess = Nothing
  51.     Set db = Nothing
  52. End Sub
Any suggestions? If it can't be done, that is also an acceptable answer, as I am able to use the current method for my purposes--it's just a little clumsy for my tastes.

Thanks for the hepp!
Nov 28 '18 #1

✓ answered by NeoPa

Ah. I see what you're getting at now. No.

Forms and Controls do, indeed, have Properties Collections, and Controls certainly even have a FormatConditions Collection, but a FormatCondition object doesn't have a Properties Collection, no. That's not too unusual TBF. Most objects don't. It's only the main Access Objects that do as far as I can see.

To check this sort of thing out for yourself simply use F2 from the VBAIDE to open the Object Browser and select Access from the Libraries ComboBox and then type "FormatCondition" into the search ComboBox. The results should include an entry for Library=Access & Class=FormatCondition. Click on that then click on FormatCondition in the Classes box to review all the possible (visible) properties. There is none called Properties :-(

Even if you show the hidden members (Right-click | Show Hidden Members) it's not there.

13 2252
NeoPa
32,556 Expert Mod 16PB
Do you have a database I can play with in 2010 accessible format.

I feel confident I can find some answers for you but I have nothing to try it on. Even a very cut-down version would be fine without any real data in it. Just to do some playing around with.
Nov 30 '18 #2
twinnyfo
3,653 Expert Mod 2GB
You’ll have to wait until next week for a DB. Talk to you then. Thanks!
Nov 30 '18 #3
NeoPa
32,556 Expert Mod 16PB
No worries. No rush :-)
Nov 30 '18 #4
twinnyfo
3,653 Expert Mod 2GB
NeoPa,

Attached is one such report in which several text boxes have multiple Conditional Formatting conditions (all Text Boxes ending with "Pct".

This DB is "not workable" as it only contains the report itself, but assessment of the Conditional Formatting is possible.

Thanks for your review.
Attached Files
File Type: zip Conditional Formatting.zip (26.2 KB, 56 views)
Dec 3 '18 #5
NeoPa
32,556 Expert Mod 16PB
Thanks for that Twinny.

I'm out of time for now but will try to look into it later in the week.

PS. I have the database now so feel free to remove it if you don't want it shared generally.
Dec 3 '18 #6
twinnyfo
3,653 Expert Mod 2GB
Thanks, friend!

Nothing in that DB, so it can stay.

Hope your holiday season is going well!
Dec 3 '18 #7
NeoPa
32,556 Expert Mod 16PB
I've looked into this now Twinny.

It seems that your fundamental question of why can't you list through the .Properties of any Control has the simple answer that Conditional Formatting is not handled within Access as Properties, but rather as a completely separate Collection altogether (FormatConditions). Is that really what you were after? It seems you already knew that.

In short - it seems that, while your original requirement is clearly impossible, something very similar does exactly the same :
Expand|Select|Wrap|Line Numbers
  1. For Each fc in ctl.FormatConditions
  2.     'Do what you wish here
  3. Next fc
Is there something else you were after or is that helpful?
Dec 8 '18 #8
NeoPa
32,556 Expert Mod 16PB
Something about your database kept playing SillyB*ggers with me and refused to save my code so I had to create a new one and type it all out again.

Nevertheless, I put together some code that I think illustrates the simplicity of the concept. Obviously you can include what you choose of the information but I found my reduced list helpful as an overview. Note that I used the index approach rather than the For ... Each one. This was so that we could also list the index value for each Control.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. 'ListFC() lists all FormatConditions for all Controls in a Form/Report object.
  5. Public Sub ListFC(objVar As Object)
  6.     Dim lngIx As Long
  7.     Dim ctlVar As Control
  8.  
  9.     If (Not TypeOf objVar Is Form) _
  10.     And (Not TypeOf objVar Is Report) Then _
  11.         Exit Sub
  12.     For Each ctlVar In objVar.Controls
  13.         If HasFC(ctlVar) Then
  14.             For lngIx = 0 To ctlVar.FormatConditions.Count - 1
  15.                 With ctlVar.FormatConditions(lngIx)
  16.                     Debug.Print Replace("Ctl Name=%CN;", "%CN", ctlVar.Name);
  17.                     Debug.Print Replace(" Index=%IX;", "%IX", lngIx);
  18.                     Debug.Print Replace(" Op=%OP;", "%OP", .Operator);
  19.                     Debug.Print Replace(" Type=%TY;", "%TY", .Type);
  20.                     Debug.Print Replace(" Exp1=%X1;", "%X1", .Expression1);
  21.                     If .Operator < 2 Then _
  22.                         Debug.Print Replace(" Exp2=%X2;" _
  23.                                           , "%X2", CStr(.Expression2));
  24.                     Debug.Print Replace(" ForeColor=%FC;", "%FC", .ForeColor);
  25.                     Debug.Print Replace(" BackColor=%BC;", "%BC", .BackColor);
  26.                     Debug.Print Replace(" Enabled=%EN", "%EN", .Enabled)
  27.                 End With
  28.             Next lngIx
  29.         End If
  30.     Next ctlVar
  31. End Sub
  32.  
  33. 'HasFC() returns True if ctlVar has a FormatConditions Collection.
  34. Private Function HasFC(ctlVar As Control) As Boolean
  35.     Dim lngVar As Long
  36.  
  37.     On Error Resume Next
  38.     lngVar = ctlVar.FormatConditions.Count
  39.     HasFC = (Err.Number = 0)
  40. End Function
Expand|Select|Wrap|Line Numbers
  1. Ctl Name=txtReceivedPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  2. Ctl Name=txtReceivedPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  3. Ctl Name=txtReceivedPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  4. Ctl Name=txtPRFReviewPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  5. Ctl Name=txtPRFReviewPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  6. Ctl Name=txtPRFReviewPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  7. Ctl Name=txtA1KPReviewPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  8. Ctl Name=txtA1KPReviewPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  9. Ctl Name=txtA1KPReviewPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  10. Ctl Name=txtDiscSentPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  11. Ctl Name=txtDiscSentPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  12. Ctl Name=txtDiscSentPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  13. Ctl Name=txtCompletePct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  14. Ctl Name=txtCompletePct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  15. Ctl Name=txtCompletePct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  16. Ctl Name=txtBulletCheckersPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  17. Ctl Name=txtBulletCheckersPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  18. Ctl Name=txtBulletCheckersPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  19. Ctl Name=txtImpPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  20. Ctl Name=txtImpPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  21. Ctl Name=txtImpPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  22. Ctl Name=txtTotalReceivedPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  23. Ctl Name=txtTotalReceivedPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  24. Ctl Name=txtTotalReceivedPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  25. Ctl Name=txtTotalPRFReviewedPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  26. Ctl Name=txtTotalPRFReviewedPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  27. Ctl Name=txtTotalPRFReviewedPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  28. Ctl Name=txtTotalA1KPReviewPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  29. Ctl Name=txtTotalA1KPReviewPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  30. Ctl Name=txtTotalA1KPReviewPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  31. Ctl Name=txtTotalDiscSentPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  32. Ctl Name=txtTotalDiscSentPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  33. Ctl Name=txtTotalDiscSentPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  34. Ctl Name=txtTotalCompletePct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  35. Ctl Name=txtTotalCompletePct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  36. Ctl Name=txtTotalCompletePct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  37. Ctl Name=txtTotalBulletCheckersPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  38. Ctl Name=txtTotalBulletCheckersPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  39. Ctl Name=txtTotalBulletCheckersPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
  40. Ctl Name=txtTotalImpPct; Index=0; Op=5; Type=0; Exp1=0.5; ForeColor=0; BackColor=2366701; Enabled=True
  41. Ctl Name=txtTotalImpPct; Index=1; Op=5; Type=0; Exp1=0.9; ForeColor=0; BackColor=62207; Enabled=True
  42. Ctl Name=txtTotalImpPct; Index=2; Op=5; Type=0; Exp1=1; ForeColor=0; BackColor=5026082; Enabled=True
Bear in mind, for such logic, you only need two FormatConditions and a default format ;-)
Dec 8 '18 #9
twinnyfo
3,653 Expert Mod 2GB
NeoPa,

From your post in #8, you will see that is exactly what I have in the original block of Code. However, if you look at lines 24-38 of that original block of Code, there appears to be no way to gather those values than to list each one out separately. One must specifically ask for the value of .BackColor to get that value.

I would have expected something like this:

Expand|Select|Wrap|Line Numbers
  1. For Each fc in ctl.FormatConditions
  2.     For Each prp in fc.Properties
  3.         'Do what I wish
  4.     Next prp
  5. Next fc
But, there is no "Property" or other characteristic that can be run through, like other objects. This may just be something unavailable in Access (at this time, anyway).
Dec 10 '18 #10
NeoPa
32,556 Expert Mod 16PB
Ah. I see what you're getting at now. No.

Forms and Controls do, indeed, have Properties Collections, and Controls certainly even have a FormatConditions Collection, but a FormatCondition object doesn't have a Properties Collection, no. That's not too unusual TBF. Most objects don't. It's only the main Access Objects that do as far as I can see.

To check this sort of thing out for yourself simply use F2 from the VBAIDE to open the Object Browser and select Access from the Libraries ComboBox and then type "FormatCondition" into the search ComboBox. The results should include an entry for Library=Access & Class=FormatCondition. Click on that then click on FormatCondition in the Classes box to review all the possible (visible) properties. There is none called Properties :-(

Even if you show the hidden members (Right-click | Show Hidden Members) it's not there.
Dec 10 '18 #11
NeoPa
32,556 Expert Mod 16PB
I've updated the title to make it clearer what to expect of the thread for those searching for a similar problem.
Dec 10 '18 #12
twinnyfo
3,653 Expert Mod 2GB
Thanks Brother!

I was expecting this result, as I had been through all the surface possibilities. I was just hoping that maybe you knew of some magical “behind the curtain” method to run through these in one line of code.

However, what I have works, and it is fairly straightforward. Just not as neat as I would have desired.

Thanks for the hepp!

P.S. Even though it is not a “solution”, I’ve marked your response as the best answer, as it does answer the question if it is possible.
Dec 11 '18 #13
NeoPa
32,556 Expert Mod 16PB
TwinnyFo:
P.S. Even though it is not a “solution”, I’ve marked your response as the best answer, as it does answer the question if it is possible.
And that's exactly why that's appropriate to do. Others looking for the same help can peruse the thread if they choose, but will see immediately the precise answer they need first.
Dec 11 '18 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
3
by: Andante.in.Blue | last post by:
Hello everyone! I'm building a form in Access 97 and I want to to show a special icon if the record has been marked as deleted. Obviously, I don't want the icon to show if the record was not...
4
by: Bradley | last post by:
I have an A2000 database in which I have a continuous form with a tick box. There is also a text box with a conditional format that is based on the expression , if it's true then change the...
8
by: Dimitri Furman | last post by:
Given: Access 2002/2003 A subform in datasheet or continuous view, placed on a tab page (this last may or may not matter) Conditional formatting applied to some controls on the subform - format...
5
by: Andrew Chanter | last post by:
Does anyone know a way you can use conditional formatting to create a banded style view as is commonly seen on the internet. (In othe words the first record appears on a gray background, the 2nd...
2
by: jodyblau | last post by:
I'm not certain that what I am trying to do is possible; in any event I haven't been able to figure it out. Here is what I am trying to do: I have one table that has a list of cases I'm working...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
11
by: tg989 | last post by:
Okay, here goes. Continuous forms... possibly the best feature of access. The only downside is this: the only way to have a conditional evaluation run on each record invididually is by...
4
by: slinky | last post by:
Thanks in advance... I have a continuous style form with a field for each record called "STATUS". I simply want to have the form load and if the value of the textbox is "Inactive" I want the...
10
by: Lyn | last post by:
Hi, I would like to make a bound text box not visible if it is empty (not just disable it). This option is not available from the standard conditional formatting feature (at least, not that I can...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.