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

    Isit possible to embed a variable when specifying a control?

    I have created this Function which highlights the labels of selected Option buttons. It is invoked whenever one either clicks a different button (i.e. vehicle direction) and when the 'Current' Event is triggered.



    Public Function Format_Direction_Display(Direction As Integer)
    Dim Black As Long
    Dim Red As Long
    Red = RGB(235, 0, 0)
    Black = RGB(0, 0, 0)


    Select Case Direction


    Case 1:
    Forms![Accident Picker]![D1NorthLabel].ForeColor = Red
    Forms![Accident Picker]![D1NorthLabel].FontBold = True
    Case 2:
    Forms![Accident Picker]![D1NorthEastLabel].ForeColor = Red
    Forms![Accident Picker]![D1NorthEastLabel].FontBold = True
    Case 3:
    Forms![Accident Picker]![D1EastLabel].ForeColor = Red
    Forms![Accident Picker]![D1EastLabel].FontBold = True
    .... and so on through 9 possible cases (8 valid directions and one for 'unknown')

    It works fine, but here's the thing. There can be up to three vehicles and each one has its own little direction selection Option Group. The 1's in the above code (D1...) stand for the vehicle number, so this code explicitly handles Vehicle 1. Is there a way to utilize a passed variable for the vehicle number to replace the 1's so that this same function can be called for all three vehicles, or will I have to replicate the code using 2's and 3's?

    Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    Forms![Accident Picker].Controls("D" & Variable & "NorthLabel).ForeColor = Red
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    J Bhujanga is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2016
    Location
    Colorado
    Posts
    27
    That does the trick with the minor correction of adding another quote after NorthLabel.
    Thanks.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, had a brain cramp. Glad you saw the problem.
    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. Replies: 3
    Last Post: 11-30-2016, 07:18 PM
  2. passing a control name as as variable
    By newbieX in forum Programming
    Replies: 3
    Last Post: 09-26-2014, 02:06 PM
  3. Control variable is Null
    By ngruson in forum Access
    Replies: 2
    Last Post: 04-21-2010, 10:27 AM
  4. Using a string variable to specify a control
    By Gerry in forum Programming
    Replies: 3
    Last Post: 04-14-2010, 02:28 PM
  5. using forms control as report variable
    By Seven in forum Reports
    Replies: 3
    Last Post: 12-19-2009, 04:04 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