Connecting Tech Pros Worldwide Help | Site Map

I'm trying to list controls in immediate window... what's wrong with this code?

  #1  
Old November 12th, 2005, 06:16 PM
MLH
Guest
 
Posts: n/a
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?
  #2  
Old November 12th, 2005, 06:16 PM
Allen Browne
Guest
 
Posts: n/a

re: I'm trying to list controls in immediate window... what's wrong with this code?


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]


  #3  
Old November 12th, 2005, 06:16 PM
MLH
Guest
 
Posts: n/a

re: I'm trying to list controls in immediate window... what's wrong with this code?


I found that my code works fine if the form I'm polling
is open. If its closed, I get the error. If its open in either
form view or design view, the code runs as expected.
Is that normally what one should expect?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxx


On Fri, 26 Dec 2003 11:03:05 +0800, "Allen Browne"
<AllenBrowne@SeeSig.Invalid> wrote:
[color=blue]
>Dim ctl As Control
>Dim strWhichForm As String
>
>strWhichForm = InputBox$("What form?")
>For each ctl In Forms(strWhichForm).Controls
> Debug.Print ctl.Name
>Next[/color]

  #4  
Old November 12th, 2005, 06:16 PM
Tom van Stiphout
Guest
 
Posts: n/a

re: I'm trying to list controls in immediate window... what's wrong with this code?


On Thu, 25 Dec 2003 22:12:40 -0500, MLH <CRCI@NorthState.net> wrote:

Yes. As the docs say, the Forms collection is the list of running
forms. They don't have to be visible, so DoCmd.OpenForm
"myform",,,acFormReadOnly is an option.

Closed forms are accessed through the Documents collection.

-Tom.



[color=blue]
>I found that my code works fine if the form I'm polling
>is open. If its closed, I get the error. If its open in either
>form view or design view, the code runs as expected.
>Is that normally what one should expect?
>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx
>
>
>On Fri, 26 Dec 2003 11:03:05 +0800, "Allen Browne"
><AllenBrowne@SeeSig.Invalid> wrote:
>[color=green]
>>Dim ctl As Control
>>Dim strWhichForm As String
>>
>>strWhichForm = InputBox$("What form?")
>>For each ctl In Forms(strWhichForm).Controls
>> Debug.Print ctl.Name
>>Next[/color][/color]

  #5  
Old November 12th, 2005, 06:16 PM
tom
Guest
 
Posts: n/a

re: I'm trying to list controls in immediate window... what's wrong with this code?


Yes, the Forms collection only contains open forms.
In your code, you could check to see if the form is open, and, if not,
open it hidden (and then close it when you're done).

-td
[color=blue]
> I found that my code works fine if the form I'm polling
> is open. If its closed, I get the error. If its open in either
> form view or design view, the code runs as expected.
> Is that normally what one should expect?[/color]
  #6  
Old November 12th, 2005, 06:17 PM
David W. Fenton
Guest
 
Posts: n/a

re: I'm trying to list controls in immediate window... what's wrong with this code?


tom7744@no.spam.cox.net (Tom van Stiphout) wrote in
<8tdnuvgslic950n7up182kqteqi9ej4g8v@4ax.com>:
[color=blue]
>On Thu, 25 Dec 2003 22:12:40 -0500, MLH <CRCI@NorthState.net>
>wrote:
>
>Yes. As the docs say, the Forms collection is the list of running
>forms. They don't have to be visible, so DoCmd.OpenForm
>"myform",,,acFormReadOnly is an option.
>
>Closed forms are accessed through the Documents collection.[/color]

In Access97 and before, yes.

In A2K and later, you can use Project.AllForms("YourForm") to get
to all forms, unopened or not.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
  #7  
Old November 12th, 2005, 06:17 PM
Tom van Stiphout
Guest
 
Posts: n/a

re: I'm trying to list controls in immediate window... what's wrong with this code?


On Fri, 26 Dec 2003 20:24:44 GMT, dXXXfenton@bway.net.invalid (David
W. Fenton) wrote:

Indeed. The CurrentProject object is a nice addition, and also works
in ADPs.
-Tom.

[color=blue]
>tom7744@no.spam.cox.net (Tom van Stiphout) wrote in
><8tdnuvgslic950n7up182kqteqi9ej4g8v@4ax.com>:
>[color=green]
>>On Thu, 25 Dec 2003 22:12:40 -0500, MLH <CRCI@NorthState.net>
>>wrote:
>>
>>Yes. As the docs say, the Forms collection is the list of running
>>forms. They don't have to be visible, so DoCmd.OpenForm
>>"myform",,,acFormReadOnly is an option.
>>
>>Closed forms are accessed through the Documents collection.[/color]
>
>In Access97 and before, yes.
>
>In A2K and later, you can use Project.AllForms("YourForm") to get
>to all forms, unopened or not.[/color]

  #8  
Old November 12th, 2005, 06:58 PM
MLH
Guest
 
Posts: n/a

re: I'm trying to list controls in immediate window... what's wrong with this code?


On Thu, 25 Dec 2003 21:25:11 -0700, Tom van Stiphout
<tom7744@no.spam.cox.net> wrote:
[color=blue]
>On Thu, 25 Dec 2003 22:12:40 -0500, MLH <CRCI@NorthState.net> wrote:
>
>Yes. As the docs say, the Forms collection is the list of running
>forms. They don't have to be visible, so DoCmd.OpenForm
>"myform",,,acFormReadOnly is an option.
>[/color]
And a very good one, I might add. Thx Tom.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net frameword Resources ( vb.net , asp.net etc...) shamirza answers 0 January 17th, 2007 08:05 AM
How to avoid lifecycle hacks? Homam answers 11 November 19th, 2005 06:41 AM
Recordset in subform based on field in parent form Lyn answers 25 November 13th, 2005 12:52 AM