Results 1 to 2 of 2
  1. #1
    PCarra is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    10

    Refering to a label control in a form using an array variable

    I am trying to refer to a label control using an Array I have populated with the names of my labels. When I open my form I get a Run-time error '438' Object doesn't support this property or method. What method should I use to loop through the labels using a variable name? Thank you in advance for your help!

    Dim MonthArr
    MonthArr = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
    Dim MonthCounter As Integer
    MonthCounter = Month(Now())
    Dim YearCounter As Integer
    YearCounter = Year(Now())
    Dim LblArr
    LblArr = Array(LastMonthsMaxlbl, CurrentMonthlbl, CurrMonthPlus1)
    Dim LblCounter As Integer


    For LblCounter = 0 To 2
    Forms(subfrmForecast).Controls(LblArr(LblCounter)) .Caption = MonthArr(MonthCounter - 2) & " " & CStr(YearCounter) & " BPS"
    MonthCounter = MonthCounter + 1
    If MonthCounter = 12 Then
    YearCounter = YearCounter + 1


    MonthCounter = 0
    End If
    Next

  2. #2
    PCarra is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    10
    I found the solution:

    Dim MonthArr
    MonthArr = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
    Dim MonthCounter As Integer
    MonthCounter = 3
    Dim YearCounter As Integer
    YearCounter = 2019
    Dim LblCounter As Integer


    For LblCounter = 0 To 18
    Me.Controls("Monthlbl" & LblCounter).Caption = MonthArr(MonthCounter) & " " & CStr(YearCounter) & " BPS"
    If MonthCounter = 11 Then
    YearCounter = YearCounter + 1
    MonthCounter = 0
    Else
    MonthCounter = MonthCounter + 1
    End If
    Next

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

Similar Threads

  1. inserting a variable into a label
    By Jen0dorf in forum Access
    Replies: 4
    Last Post: 04-02-2016, 11:02 AM
  2. Replies: 8
    Last Post: 06-19-2015, 02:19 AM
  3. using dynamic label/variable name
    By Eef in forum Programming
    Replies: 4
    Last Post: 10-19-2014, 06:24 AM
  4. Variable within form control reference
    By Tyork in forum Programming
    Replies: 2
    Last Post: 10-13-2010, 09:55 AM
  5. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 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