Results 1 to 6 of 6
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479

    Command to Set Back Color

    If i know the table field Index number, how can I set that controls back color on the Form ?

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    You would at least need to know the field name because that's the value of the control controlsource property. From what I remember of your prior post(s) about field index I'd say it's something you shouldn't be bothered trying to use at all.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Would you elaborate please as it is not very clear.... The table index number has nothing to do with a form; you can get the field name using the the index number using tabledef.fields(index).Name and then you would need to loop through the form controls and compare the control.controlsource property to the field name. If found then set the control's back color to whatever you want.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    Yes @Micron, I do know the field name. I thought the other posts solution would help but got a bit bogged down. I can't not bother to try as I need it!!
    What you and @Gicu advise is correct, and I think we're all okay now.
    Code:
    Function ReturnControlNameFor(othername) As String    Dim ctl As Control
        For Each ctl In Form_frmShowRecord.Controls
            If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
                If othername = ctl.ControlSource Then
                    ReturnControlNameFor = ctl.name
                    Exit Function
                End If
            End If
        Next
    End Function
    I previously had a lookup table but I this this is more 'correct'.
    Thanks for replies.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Form is bound to table?

    Are controls named same as field names?

    Say x is the known index value, consider:
    Code:
    Me.Controls(CurrentDb.TableDefs("tablename").Fields(x).Name).Backcolor = vbRed
    Why would the index be known and not the field name?
    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.

  6. #6
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    479
    Thank you @June7. No, they're not the same (maybe they could/should be?) but are the same as their control source.
    I did have both index and field name.

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

Similar Threads

  1. Command Button Back Color
    By GraeagleBill in forum Forms
    Replies: 4
    Last Post: 03-22-2020, 12:40 PM
  2. Replies: 4
    Last Post: 11-15-2017, 05:29 PM
  3. Conditional back color of box.
    By BatmanMR287 in forum Reports
    Replies: 3
    Last Post: 07-12-2015, 02:39 PM
  4. alternate back color not working
    By dbaldwin117 in forum Reports
    Replies: 3
    Last Post: 02-25-2013, 01:33 PM
  5. Form Back Color, screen only?
    By LostInAccess in forum Forms
    Replies: 2
    Last Post: 07-19-2012, 08: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