Results 1 to 7 of 7
  1. #1
    riaarora is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    25

    Conditional Formatting

    Hi


    I'm trying to apply conditonal formatting with TrafficLights using below access VBA but getting error "object doesn't support this property or method". I'm new to Access VBA please let me know what I'm doing wrong.
    Code:
    Sub setRAGStatusFontColorIcon(strRange As String)
        Dim objISet As Excel.IconSetCondition
        With objXLApp
            .FormatConditions.Delete
            Set objISet = .FormatConditions.AddIconSetCondition
            .FormatConditions(.FormatConditions.count).SetFirstPriority
            With objISet
                .ReverseOrder = True
                .ShowIconOnly = False
                .IconSet = ActiveWorkbook.IconSets(xl3TrafficLights1)
                With .IconCriteria(2)
                    .Type = xlConditionValueFormula
                    .Value = 1
                    .Operator = 5
                End With
                With .IconCriteria(3)
                    .Type = xlConditionValueFormula
                    .Value = 0.9
                    .Operator = 5
                End With
            End With
        End With
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    You have posted VBA/Excel code in an Access forum. You might have better luck posting to an Excel forum.

    What is 'Traffic Lights'?

    Why are you setting conditional format with code and not directly with the spreadsheet?

    Exactly which line is triggering the error?

    Want to provide the files for analysis? Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    1) what is objXLapp? Is it defined and set somewhere outside that Sub? If no, this is the error - Access does not know what objXLapp is.

    2) which line of code is generating the error, as June 7 pointed out? Are you able to enter the debug mode when the error occurs?

    3) you have strRange as a parameter to the Sub, but you never use it - is that intentional?

    Do you have Option Explicit as one of the options at the top of your code module? If not, I suggest you add it and then re-compile your code - you'd be suprised at the errors that might reveal.

    HTH

    John

  4. #4
    riaarora is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    25
    There is no compilation error. Please find below the code

    Variables outside the sub

    Code:
    Option Compare Database
    Option Explicit
    
    Public appAccess As Access.Application
    'Dim objXLApp As Object 'Excel.Application
    Dim objXLApp As Excel.Application
    'Dim objXLWorkbook As Object 'Excel.Workbook
    Dim objXLWorkbook As Excel.Workbook
    'Dim objXLSheet As Object 'Excel.Worksheet
    Dim objXLSheet As Excel.Worksheet

    There is another piece of code to create the Excel file and populate the data from ACCESS to Excel, that is working fine. After populating the numbers from Access to Excel I'm formatting using ACCESS VBA.

    Code:
    Sub setRAGStatusFontColorIcon(strRange As String)
        Dim objISet As Excel.IconSetCondition
        With objXLApp
            Set objISet = .FormatConditions.AddIconSetCondition              '---> ERROR
            .FormatConditions(.FormatConditions.count).SetFirstPriority      '---> ERROR
            With objISet
                .ReverseOrder = True
                .ShowIconOnly = False
                .IconSet = ActiveWorkbook.IconSets(xl3TrafficLights1)
                With .IconCriteria(2)
                    .Type = xlConditionValueFormula
                    .Value = 1
                    .Operator = 5
                End With
                With .IconCriteria(3)
                    .Type = xlConditionValueFormula
                    .Value = 0.9
                    .Operator = 5
                End With
            End With
        End With

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    What version of Excel? I've never used it, but according to Help AddIconSetCondition came in with 2007. Your profile says Access 2003, so if your Excel version is also 2003, that wouldn't be available.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I almost understand what this code is doing. Perhaps you could offer more info.

    According to
    http://social.msdn.microsoft.com/For...f-19360dc765f4
    http://office.microsoft.com/en-us/ex...080551788.aspx
    FormatConditions.AddIconSetCondition is method of a Range, not application object.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    riaarora is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    25
    I'm using Access 2007 and Excel 2007

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

Similar Threads

  1. Conditional Formatting
    By bellevue in forum Forms
    Replies: 4
    Last Post: 05-17-2012, 06:03 AM
  2. Conditional Formatting
    By ccordner in forum Reports
    Replies: 6
    Last Post: 01-09-2012, 04:12 PM
  3. Conditional Formatting
    By Paul H in forum Reports
    Replies: 3
    Last Post: 11-07-2011, 11:59 AM
  4. Conditional Formatting
    By Desstro in forum Programming
    Replies: 3
    Last Post: 12-01-2010, 09:52 PM
  5. Conditional Formatting
    By cevatyildiz in forum Forms
    Replies: 8
    Last Post: 04-30-2010, 12:01 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