If i know the table field Index number, how can I set that controls back color on the Form ?
If i know the table field Index number, how can I set that controls back color on the Form ?
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.
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,
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.
I previously had a lookup table but I this this is more 'correct'.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
Thanks for replies.
Form is bound to table?
Are controls named same as field names?
Say x is the known index value, consider:
Why would the index be known and not the field name?Code:Me.Controls(CurrentDb.TableDefs("tablename").Fields(x).Name).Backcolor = vbRed
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.
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.