John Shaw
John Shaw

Reputation: 348

How to cycle through Textbox Controls Access VBA

I wanted a code that would cycle thru the names of text box controls on a form whose Visible = true. I know this code is constructed incorrectly, but I need to ask if anyone can point me in the right direction.

Public Sub TxtBoxNamevisible(ByRef pfrm As Form)
Dim ctl As Control
Dim txtbx As TextBox

For Each txtbx In pfrm.Controls.visible = true
MsgBox txtbx.Name
Next txtbx
End Sub

Upvotes: 1

Views: 956

Answers (1)

HansUp
HansUp

Reputation: 97101

pfrm.Controls.visible does not compile because Controls is a collection. Visible is a supported property for members of that collection, but not supported on the collection itself.

Loop through pfrm.Controls, check whether each of them is a Visible text box, and MsgBox the names of those which are ...

Dim ctl As Control
For Each ctl In pfrm.Controls
    If ctl.ControlType = acTextBox And ctl.Visible = True Then
        MsgBox ctl.Name
    End If
Next ctl

Upvotes: 3

Related Questions