Results 1 to 13 of 13
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Conditional formatting not recognizing rule

    bolColor is DIM'd boolean and global to the form and I've observed it to be true in Debug. Also, I've verified that UNIT is in fact a valid field in the RecordSource of the form. I do not know why the rule does not "fire" when the two conditions are clearly present when the form paints. I don't know of any form property that affects use of conditional formatting. I even tried reducing the condition to [bolColor] = True with out regards to the value of UNIT, but it still doesn't "fire".


    Click image for larger version. 

Name:	000.jpg 
Views:	15 
Size:	26.2 KB 
ID:	47626

    Must be something wrong with bolColor, as when I set the rule expression to [UNIT] > 0 then the condition takes affect. Don't spend any time until I investigate more deeply. I'll post back later with whatever I find, good or bad.

  2. #2
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    If I set bolColor = True in the OnOpen Event and never reset it as conditions change, I still can't get the rule to "fire".

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    There's something wrong with the expression. I put a command button on the form's header section and investigated the value of bolColor when the conditions are such that the conditional formatting should "fire". I can write a function to return the current condition, but that ought not be necessary. Any ideas why the expression won't get the job done?

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    Is it the value of the boolean or is it something else in the expression? Here's a tip: to test whether or not something can work with a T/F condition, create your own static condition such as 2=2. Works in code, should work in cf, methinks. If it works it would seem that in this case you'd know the issue is the visibility of the variable OR the value of the variable. Might be better to have a field on the form you can refer to, but I suspect that would have to be bound (I'm assuming you're working in a cf or datasheet).

    Other thing to investigate is if there is a syntax for returning module level variable value because I thought cf conditions like that work with records, and your variable is not a record.

    EDIT - If the issue is visibility and there's no syntax for referring to a mod level variable (or at least one that would work with cf), you probably could do this in code where you will be able to grab the boolean value.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    WOW! Even this doesn't work:

    Click image for larger version. 

Name:	001.jpg 
Views:	13 
Size:	20.3 KB 
ID:	47629

    Code:
    Public Function ResWait(bolState As Boolean, UnitNum As Integer) As Boolean
    If bolState = True And UnitNum > 0 Then
        ResWait = True
    Else
        ResWait = False
    End If
    
    
    End Function

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    2=2. Works in code, should work in cf,
    Yes, I thought I'd essentially done a test like you suggest with a simple [UNIT]>0, knowing for certain that condition exists with all the records in the Recordsource.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    I reviewed just now and can't see where you said or showed that you put just [UNIT]>0 in the cf dialog box
    I'm saying start simple and test "Expression is: 2=2" and nothing else. If that works it tells you that there's probably nothing like corruption going on.
    Then assuming you have records where UNIT < 0 I'd try only [UNIT]>0 (which as I noted, I cannot see where you tried that). If those work then maybe the issue is the visibility of your module level variable (which is not part of the recordset that I though cf was based on).
    Baby steps.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    [UNIT]>0 by itself worked perfectly as noted in #6. bolColor is dim'd at the form's global level, so it should be available within any of the form's filtered displays. I moved the Dim of bolColor to Public in my app's global module and verified via a temporary command button that bolColor is in fact True, but still "no cigar". Even [bolColor] = True by itself doesn't cause the condition to "fire", with or without the brackets.
    I'll try to add conditional formatting to the same controls in a back-level of the app to see if perhaps there's some sort of corruption at hand.
    EDIT:
    Fails to take affect when attempted in previous version of the app.
    EDIT2: Fails with different control and a child form. I just can't get conditional formatting to respond to a Boolean module variable.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Created a new accdb DB and copied all the elements of the troublesome DB but issue followed. Even tried to test the content of a text box (below), but that is ignored as well. I'm stumped

    Click image for larger version. 

Name:	002.jpg 
Views:	10 
Size:	27.4 KB 
ID:	47631

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    I think you'll have to set the cf condition to an expression that references a function and do it in code. I tried a few things like form_form6.publicVariableName and Forms!form6.publicVariableName and it just doesn't seem to be withing the scope of the cf part of Access. Pretty sure a function would work though, but if the form module level variable isn't within the scope of cf, I suspect the function won't be either, so I'd stick it in a standard module. Then again, I might try the form module first just for fun, but would be surprised if it worked.
    Last edited by Micron; 04-05-2022 at 11:55 PM. Reason: added comment
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    Well, as per paragraph 2 & 3 in post 4, the issue would seem to be one of scope. This does work in a standard module, but not in the form module ...

    Code:
    Public CFboolean As Boolean
    _______________________________
    
    Public Function TestCf() As Boolean
    If CFboolean = True Then TestCf = True
    
    End Function
    Expression is testcf()=True

    ... as long as you set the variable to True somehow. I used immediate window.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,007
    Tempvars work ?
    Attached Thumbnails Attached Thumbnails blnColour.PNG  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  13. #13
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    As I posted in #5, I tried to resolve the issue with a function, like Micron's:
    Code:
    Public CFboolean As Boolean_______________________________
    
    Public Function TestCf() As Boolean
    If CFboolean = True Then TestCf = True End Function
    I couldn't get the function approach to work whether I put the code in a general module or the form's module.

    Anyway, it occurred to me that there were fields in the RecordSource that could be investigated allowing the inclusion of a "flag field" that I could use in combination with [UNIT] to trigger the desired formatting. With that, I have found an acceptable solution, certainly not the one I expected.
    Thanks guys,
    Bill

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-12-2015, 10:46 AM
  2. Replies: 1
    Last Post: 11-19-2014, 07:19 AM
  3. Replies: 6
    Last Post: 05-26-2013, 09:10 PM
  4. Conditional Formatting
    By Paul H in forum Reports
    Replies: 3
    Last Post: 11-07-2011, 11:59 AM
  5. Conditional Formatting
    By Desstro in forum Programming
    Replies: 3
    Last Post: 12-01-2010, 09:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums