Dim ctl As Control
Dim strWhichForm As String
strWhichForm = InputBox$("What form?")
For each ctl In Forms(strWhichForm).Controls
Debug.Print ctl.Name
Next
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"MLH" <CRCI@NorthState.net> wrote in message
news:qe8nuv03lmje8b1cfvs48k62b99nlanoev@4ax.com...[color=blue]
> Sub ListControlsBttn_Click ()
> '************************************************* ************************
> ' Purpose: Run the Controls Collection for user-specified form.
> ' The controls collection is a form's default collection.
> '************************************************* ************************
> On Error GoTo ListControlsBttn_ClickError
> Dim ThisForm As String, Msg As String, Title As String, Defvalue As
> String
> ThisForm = Me.Name
> Dim i As Integer, intHowmany As Integer, WhichForm As String
>
> Msg = "Enter form name." ' Set prompt.
> Title = "Form Name?" ' Set title.
> Defvalue = "frmListThings" ' Set default return
> value.
> WhichForm = InputBox$(Msg, Title, Defvalue) ' Get user input.
> If WhichForm = "" Then Exit Sub
> For i = 0 To Forms(WhichForm).Count - 1
> intHowmany = intHowmany + 1
> Debug.Print intHowmany; ") "; Forms(WhichForm)(i).Name
> Next i
>
> ExitButton11_Click:
> Exit Sub
>
> ListControlsBttn_ClickError:
> Dim r As String, k As String, Message3 As String
> r = "The following unexpected error occurred in Sub
> ListControlsBttn_Click, CBF on " & ThisForm & "."
> k = CRLF & CRLF & "Error # " & Trim$(Str$(Err)) & ": " & QUOTE &
> Error$ & QUOTE
> Message3 = r & k
> MsgBox Message3, 48, "Unexpected Error - " & MyApp$ & ", rev. " &
> MY_VERSION$
> Resume ExitButton11_Click
>
> End Sub
>
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxx
> If I type in a form name, I get error #2450 (invalid reference to form
> 'frmMyForm'). If I accept the default form name (frmListThings) I get
> what I want. What's wrong?[/color]