Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to set the value or

Status
Not open for further replies.

thegameoflife

Programmer
Dec 5, 2001
206
US
Is it possible to set the value or text of a text box using this code or some other code.

i.e. When the form is opened have all the txtboxes say "hello"???


Code:
Sub test()
    Dim ctl As Control

       For Each ctl In frm.Controls
        
        If ctl.ControlType = acTextBox Then
            
            With ctl
                .SetFocus
                .Enabled = True
            End With
         End If
    Next ctl
End Sub
 
If you do not mind text boxes with the same name then try using an array of text boxes. I have not tried this in VBA but it works in VB

ie
txtbox(0)
txtbox(1)
txtbox(2)
.....
txtbox(9)


' code for 10 boxes
dim i as integer 'used as a pointer

sub form_load()
for i = 0 to 9
txtbox(i).text = "hello World"
next i
end sub


hope this help

Geo45
 
This works as you require:

Sub test()
Dim ctl As Control, frm As Form

Set frm = Me.Form

For Each ctl In frm.Controls

If ctl.ControlType = acTextBox Then

With ctl
.SetFocus
.Value = "Hello"
.Enabled = True
End With
End If
Next ctl
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top