Results 1 to 3 of 3
  1. #1
    DDS is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Apr 2018
    Posts
    24

    Error 438 when referring to a sub

    Please excuse my inexperience...
    I have a form with 26 labels named "Bar1" to "Bar26" in the form (I'm fiddling with making a custom graph - yes I know Access has built in graph functions).
    I'm trying to work out an efficient way of making these label's backcolour property toggle between two colours when clicking them.
    I created code which actually did work when placed in one of the individual label's on click event (lbl changed to Me.Bar1) but when I move the code to a sub and try to refer to this sub I get:
    "Run-time error '438': Object doesn't support this property or method"
    I've tried many searches and tried many things but I'm stumped.
    Could someone please advise? Thanks.
    This is the code:

    Code:
    Sub barColour(lbl As Label)
        
        If lbl.BackColor = RGB(214, 220, 229) Then
            lbl.BackColor = RGB(132, 151, 176)
        ElseIf lbl.BackColor = RGB(132, 151, 176) Then
            lbl.BackColor = RGB(214, 220, 229)
        End If
        
    End Sub
    
    
    Private Sub Bar1_Click()
    
    
        barColour (Me.Bar1)
        
    End Sub


  2. #2
    DDS is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Apr 2018
    Posts
    24
    Never mind.
    I figured out away to get it to work (might not be the best solution I admit)
    This is working now:

    Code:
    Sub barColour(lblName As String)
    
    
        Dim lbl As Label
        Set lbl = Forms("OrionJobAnalysis").Controls(lblName)
        
        If lbl.BackColor = RGB(214, 220, 229) Then
            lbl.BackColor = RGB(132, 151, 176)
        ElseIf lbl.BackColor = RGB(132, 151, 176) Then
            lbl.BackColor = RGB(214, 220, 229)
        End If
        
    End Sub
    
    
    Private Sub Bar1_Click()
    
    
        barColour ("Bar1")
        
    End Sub

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Thanks for updating the thread with your solution and welcome to the site!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Referring to a form in another database
    By aytee111 in forum Programming
    Replies: 15
    Last Post: 12-07-2016, 10:32 AM
  2. Replies: 2
    Last Post: 04-20-2013, 03:37 AM
  3. Referring to range in access
    By ped in forum Access
    Replies: 11
    Last Post: 08-10-2011, 04:22 PM
  4. Referring to another table for a text box
    By hawkins in forum Reports
    Replies: 5
    Last Post: 07-05-2011, 04:14 PM
  5. Referring to objects
    By stubbly in forum Programming
    Replies: 1
    Last Post: 10-14-2009, 09:36 AM

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