473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

MLH
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?
Nov 12 '05 #1
7 2178
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" <CR**@NorthState.net> wrote in message
news:qe********************************@4ax.com...
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?

Nov 12 '05 #2
MLH
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"
<Al*********@SeeSig.Invalid> wrote:
Dim ctl As Control
Dim strWhichForm As String

strWhichForm = InputBox$("What form?")
For each ctl In Forms(strWhichForm).Controls
Debug.Print ctl.Name
Next


Nov 12 '05 #3
On Thu, 25 Dec 2003 22:12:40 -0500, MLH <CR**@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.

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"
<Al*********@SeeSig.Invalid> wrote:
Dim ctl As Control
Dim strWhichForm As String

strWhichForm = InputBox$("What form?")
For each ctl In Forms(strWhichForm).Controls
Debug.Print ctl.Name
Next


Nov 12 '05 #4
tom
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
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?

Nov 12 '05 #5
to*****@no.spam.cox.net (Tom van Stiphout) wrote in
<8t********************************@4ax.com>:
On Thu, 25 Dec 2003 22:12:40 -0500, MLH <CR**@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.


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
Nov 12 '05 #6
On Fri, 26 Dec 2003 20:24:44 GMT, dX********@bway.net.invalid (David
W. Fenton) wrote:

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

to*****@no.spam.cox.net (Tom van Stiphout) wrote in
<8t********************************@4ax.com>:
On Thu, 25 Dec 2003 22:12:40 -0500, MLH <CR**@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.


In Access97 and before, yes.

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


Nov 12 '05 #7
MLH
On Thu, 25 Dec 2003 21:25:11 -0700, Tom van Stiphout
<to*****@no.spam.cox.net> wrote:
On Thu, 25 Dec 2003 22:12:40 -0500, MLH <CR**@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.

And a very good one, I might add. Thx Tom.
Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Willam Roberts | last post by:
To me, when you enumerate, you make a list of specific items, like enumerating controls in a form. Am I missing something? I mean is there something more to the meaning of the term "enumeration" or...
2
by: Dave | last post by:
I'm getting different results when I display a value in the Output window as opposed to the Immediate window. Why? Code to recreate problem: 'Purpose: Get different results from Output...
7
by: dixie | last post by:
I have a text box on a form. In that text box is a list of people separated by a comma. Like A.Smith, L.Jones, P.Somebody, H. Somebodyelse Note, there is no full stop at the end of the list...
3
by: Russell Stevens | last post by:
Can anyone tell me how to get to the immediate window in VS2005. The help file says (when debugging) to click Debug, Windows, Immediate. There is no Immediate window listed there, nor anywhere else...
2
by: MLH | last post by:
I would like to populate a table with the following information: tblPropertySettings - the GotFocus property setting string - the LostFocus property setting string I'd like to document...
16
by: Brian D | last post by:
I have a multiple select list that is created dynamically based on a previous selection on an asp page. The first thing I do is to clear the curent option list by ...
5
by: Easystart | last post by:
Hi, Sorry for my English. English is not my native tougue. I am working in MS Access 2000 with a SQLServer 2000 Backend database. MS Access 2000 is my GUI front end that has SQLServer linked...
5
by: vul | last post by:
In VB6 I used to use Immediate Window to get or change values of variables. It is very convenient while debugging. I used drag and drop operation to paste the variable name into Immediate Window....
4
by: Armin Zingler | last post by:
Hi, I feel fooled.. In the immediate window, if I enter ? DateTime.Now.Kind I get "Unspecified {0}". The result - I expected "local" - lead to some time consuming deliberations. Today, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.