dynamically reference a textbox

spinkung

Registered User.
Local time
Today, 22:59
Joined
Dec 4, 2006
Messages
267
hi

instead of me.myTextbox1.value i want to reference the text box like this...

i = 1
Me.Controls("myTextbox" & i).Value


it's so i can assign values to specific text boxes. can it be done??

thanks.
 
So what's wrong with what you just wrote? Have you tried it out?
 
yes i get this error

object doesn't support this property or method.
 
Where did you type this code? In a sub or function within your form?
 
Are you sure that the control myTextbox1 is not the name of a label in your form?
 
actually i'll be setting the value of a checkbox, but it's the same principle.

the checkboxes are called

Me.chk_hzd_01
Me.chk_hzd_02
....
....
Me.chk_hzd_09

i want to say me.Controls("chk_hzd_0" & i).Value = -1 OR 0
 
In what event are you setting the code? In fact, let me see the entire code (wrapped in code tags).
 
Code:
' *************************************
' ***** OPEN FORM *********************
' *************************************
Private Sub Form_Open(Cancel As Integer)
    NexusDataB_bulk_Initialiser
End Sub

' *************************************
' ***** STORE NEXUS B INITIALISER *****
' *************************************
Public Sub NexusDataB_bulk_Initialiser()

i = 1

For Each ctl In Me.Controls
    Select Case ctl.ControlType
        Case acTextBox
            If Left(ctl.Name, 7) = "SafeHaz" Then
                If CInt(Right(ctl.Name, 2)) = i Then
                    Me.Controls("chk_hzd_0" & i).Value
                End If
                i = i + 1
            End If
    End Select
Next

end sub
 
You are not assigning anything to it nor are you Msgboxing or Debug.Printing it.
 
success...

Code:
For Each ctl In Me.Controls
    Select Case ctl.ControlType
        Case acTextBox
            If Not Left(Me.Controls(ctl.Name).Value, 1) = " " Then
                If Left(ctl.Name, 7) = "SafeHaz" Then
                For i = i To 9
                    If CInt(Left(Right(Trim(ctl.Value), 6), 2)) = i Then
                        Me.Controls("chk_hzd_0" & i) = -1
                    End If
                Next
                i = 1
                End If
            End If
    End Select
Next

thanks
 

Users who are viewing this thread

Back
Top Bottom