Find Control (1 Viewer)

Mihail

Registered User.
Local time
Tomorrow, 01:35
Joined
Jan 22, 2011
Messages
2,373
Hello !
I have:
1) a table (T) with fields (F1, F2, .... , Fk, .... Fn). I do not know "n"
2) a form (F) bounded to this table

I know that I have a control bounded to field Fk.

How I can find what control is ?

Thank you.

Something like this:
Code:
Dim MyCtl As Control
Dim ctl As Control
  For Each ctl In Controls
    If ctl [COLOR=Red]IsBoundedToFieldFk [/COLOR]Then
      Set MyCtl = ctl
  Exit For
    End If
  Next ctl
 

nanscombe

Registered User.
Local time
Today, 23:35
Joined
Nov 12, 2011
Messages
1,082
Are you trying to find, from inside form F:

Number of fields: Me.Recordsetclone.Fields.Count
Last field number: Me.Recordsetclone.Fields.Count - 1 (Field numbering starts at 0, not 1)

Or are you trying to find which control is bound to field fk?

I assume that you can't just look at the control source in the design view?

In your code you could test to see what ctl.ControlSource is.
 
Last edited:

Mihail

Registered User.
Local time
Tomorrow, 01:35
Joined
Jan 22, 2011
Messages
2,373
Thank you for answer, Jack, but nothing to help in find an answer. Am I missing something ?
My problem is to find a control if I know the name for the field where this control is bounded.
I have expected something like the control property:
x = ControlName.FieldWhereIsBoundName
And in x to have the field name after running the code.
 

Mihail

Registered User.
Local time
Tomorrow, 01:35
Joined
Jan 22, 2011
Messages
2,373
I have tried this
Code:
On Error Resume Next
Dim ctl As Control
    For Each ctl In Me.Controls
        Debug.Print ctl.ControlSource
    Next ctl
    
    Stop
and it works, even the intellisense do not show me the .ControlSource option for ctl.
Thank you, guys. That is what I am looking for.
 

Users who are viewing this thread

Top Bottom