Results 1 to 5 of 5
  1. #1
    J Bhujanga is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2016
    Location
    Colorado
    Posts
    27

    Calling Form Object using Variables

    I have a form on which I have 80 small boxes that represent panels on vehicles, and they are in fact located on graphic depictions of vehicles. We have two 40-character strings. Each character in the strings can be 0,1,2 or 3 representing the amount of damage to that panel. There are two strings because there are 40 possible locations on each of two vehicles.
    So, when we go to a new record, I want to set the colors of each of the panels based on the value of the corresponding character in the string. So, for example, if the 10th character is "0" then the box on panel number 10 would be invisible, if it is "3" it would be red indicating heavy damage.


    The little boxes are named DamageV1P1, DamageV1P2..... DamageV1P40, DamageV2P1..... DamageV2P39, DamageV21P40. So it's like a 2x40 array.
    I have code in the 'Current' event that works fine for setting DamageV1P1. It is:

    PanelValue = Mid(V1Damage, 1, 1) <----- V1Damage is the 40-char string described above, For 2nd vehicle it's V2Damage

    If PanelValue = 0 Then Me.DamageV1P1.Visible = False Else Me.DamageV1P1.Visible = True
    If PanelValue = 1 Then Me.DamageV1P1.BackColor = Green
    If PanelValue = 2 Then Me.DamageV1P1.BackColor = YellowOrange
    If PanelValue = 3 Then Me.DamageV1P1.BackColor = Red

    I don't want to replicate the code for all 80 panels so what I want to do is place all 5 of these statements in a double loop (1 to 2 and 1 to 40) that increments the first variable in the MID statement (no problem) and the object names (problem). Since these call out are not in quotes, I can't see how to do it like I would is, for example, this was happening inside something like Domain Aggregate call where you can close the quotes and append a variable. Everything I've tried has resulted in errors.
    I appreciate any help you can offer.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Given 2 variables:

    Me("DamageV" & Variable1 & "P" & Variable2).Visible
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Call a subroutine and send the box to it...

    Code:
    Sub runThis()
    FormatBox DamageV1p1
    FormatBox DamageV1p2
    FormatBox DamageV2p3
    End sub
    
    
    Sub FormatBox(pobj )
    
    PObj.Visible = PanelValue=0
    Select case panelvalue
         Case 1
               Pobj.backcolor = vbGreen
         Case 2
               Pobj.backcolor = vbOrange
         Case 3
               Pobj.backcolor = vbRed
    
    end select
    end sub

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    Maybe something like this:

    Dim v2, v40 as Integer
    Dim vDamage, vDamageOut as Variant

    For v2 = 1 to 2
    vDamage = "V" & v2 & "Damage"

    For v40 = 1 to 40
    vDamageOut = "DamageV" & v2 & "P" & v40
    PanelValue = Mid(vDamage, v40, 1)

    If PanelValue = 0 Then Me(vDamageOut).Visible = False Else Me(vDamageOut).Visible = True
    If PanelValue = 1 Then Me(vDamageOut).BackColor = Green
    If PanelValue = 2 Then Me(vDamageOut).BackColor = YellowOrange
    If PanelValue = 3 Then Me(vDamageOut).BackColor = Red

    Next v40
    Next v2

  5. #5
    J Bhujanga is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2016
    Location
    Colorado
    Posts
    27
    Thanks for all of your advices. It allowed me to get it working quite easily.

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

Similar Threads

  1. Using variables in another object
    By system243trd in forum Programming
    Replies: 7
    Last Post: 01-06-2016, 06:27 PM
  2. Replies: 5
    Last Post: 01-14-2015, 08:16 PM
  3. Calling sub routines No object
    By ssalem in forum Programming
    Replies: 3
    Last Post: 04-16-2013, 12:24 PM
  4. VBA Optimization - Forms in Object Variables
    By GeekInOhio in forum Programming
    Replies: 1
    Last Post: 09-18-2012, 02:28 PM
  5. Replies: 0
    Last Post: 06-14-2010, 07:19 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