a question on form.item

L

Lord Kelvan

On furthering on my question from yesterday I just want to know how
this collection is formed.

Logic demands that form.item(0) would be the first form opened then if
you open another form form.item(1) would be the ID of that form and if
you opened another form from the that forms id would be form.item(2)
then if you closed form.item(2) you would go back to the second opened
form form.item(1)

So based on this form.item(form.count-1) will always target the last
form opened. Is this correct or does this collection mess itself up
and this is not the case.

Regards
Kelvan
 
A

Arvin Meyer [MVP]

I don't think you have it quite right, but maybe I'm misunderstanding:

The Item property is not a form property, it is a property of the forms
collection, so:

form.item(form.count-1)

should really be:

forms.item(forms.count).Visible

which is refering to each item in the forms collection

Forms.Count is normally used like:

For i = 0 To Forms.Count - 1
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access
Co-author: "Access 2010 Solutions", published by Wiley
 
L

Lord Kelvan

I think you have got the short end of the stick

forms.item(forms.count) wont work because the count of forms is the
form index - 1 as the form index starts off at 0

I am attempting to target the last opened form in the collection of
forms i.e. I have 4 forms opened in my application which from my
understanding is forms.item(forms.count-1) whatever method or property
I use is irrelevant but for sake of argument lets use visible so it I
want to hide the last opened form I would use

Forms.item(forms.count-1).visible = false

My question is not if this is correct because I know this is.

My question is the collection forms.item index order always in the
order of the forms opening order or does it screw with itself and mess
up its index order so the opening order is not the order of the forms
opening.

Regards
Kelvan
 
A

Arvin Meyer [MVP]

Did you read the code:

For i = 0 To Forms.Count - 1

That's the same as:

For i = 1 To Forms.Count

Yes, hiding the last form is:

Forms.item(forms.count-1).visible = false

So what you want to do to find out is:

For i = 0 To Forms.Count - 1
Debug.Print Form.Name

and you'll see exactly the order they are addressed.
--
Arvin Meyer, MCP, MVP
Co-author: "Access 2010 Solutions", published by Wiley
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access
 
L

Lord Kelvan

Yes I know how to check which order the forms are in again that’s not
my question

I just want to know if the collection is stable as if I opened a form
and I have 3 other forms open will it make the index of that form 3
(i.e. 0,1,2,3) or is there a chance that it will for some unknown
reason make the index of that form 1.

Are there any circumstances this might happen or anything I have to
lookout for when I programme as to no destroy my application because
the last form opened for some reason because of an issue with the
collection that I don’t know about is not the last form in the
collections index.

Regards
Kelvan
 
A

Arvin Meyer [MVP]

The forms index starts with the first form opened and ends with the last. I
gave you the code snippet to check that for yourself. Many developers want
to control what happens during close down so the open a form hidden when
Access opens, then if they ever need to close everything, the code they use
is uses something like:

For i = Forms.Count - 1 To 0 Step -1
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access
Co-author: "Access 2010 Solutions", published by Wiley


Yes I know how to check which order the forms are in again that’s not
my question

I just want to know if the collection is stable as if I opened a form
and I have 3 other forms open will it make the index of that form 3
(i.e. 0,1,2,3) or is there a chance that it will for some unknown
reason make the index of that form 1.

Are there any circumstances this might happen or anything I have to
lookout for when I programme as to no destroy my application because
the last form opened for some reason because of an issue with the
collection that I don’t know about is not the last form in the
collections index.

Regards
Kelvan
 
J

Jon Lewis

I think you're slightly misunderstanding the question Arvin.

If a number of forms are opened, do they retain the same Index *order*
throughout the life of the collection? Specifically is the Item with the
highest Index in the Collection always the last Form opened? I think this
is the case Kelvan but the Index itself can change with a collection. For
example, if you remove Item(0) then all the items are shifted down one so
that what was Item 1 becomes Item 0 and so on but as far as I know the order
is not changed. This is not the case with an array which always retains
it's original Indexing and this might be a more appropriate Object for you
to work with.

HTH

Jon
 
A

Arvin Meyer [MVP]

Jon Lewis said:
I think you're slightly misunderstanding the question Arvin.

If a number of forms are opened, do they retain the same Index *order*
throughout the life of the collection?

Yes, as long as the collection is unchanged.
Specifically is the Item with the highest Index in the Collection always
the last Form opened?
Yes

I think this is the case Kelvan but the Index itself can change with a
collection. For example, if you remove Item(0) then all the items are
shifted down one so that what was Item 1 becomes Item 0 and so on but as
far as I know the order is not changed.

The order only changes as forms are deleted from and added to the
collection.
This is not the case with an array which always retains it's original
Indexing and this might be a more appropriate Object for you to work with.

An array does not change because it doesn't gain or lose elements unless it
is redim'd. It them changes unless Redim Preserve is used.

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access
Co-author: "Access 2010 Solutions", published by Wiley
 
J

Jon Lewis

Arvin Meyer said:
Yes, as long as the collection is unchanged.


The order only changes as forms are deleted from and added to the
collection.

Does the order change? This is the salient point Arvin.
You open up FormA, FormB, FormC, FormD in that order.
They then correspond to Forms.Item(0), Forms.Item(1), Forms.Item(2),
Forms.Item(3) in the Forms collection
Remove Forms.Item(3) from the collection
We're left with Forms.Item(0), Forms.Item(1), Forms.Item(2)
Is it certain that Forms.Item(0), Forms.Item(1), Forms.Item(2) correspond to
FormA, FormB, FormC in that order?
or
Remove Forms.Item(0) from the collection.
The element's are 'shifted' down.
We're left with Forms.Item(0), Forms.Item(1), Forms.Item(2)
Is it certain that Forms.Item(0), Forms.Item(1), Forms.Item(2) correspond to
FormB, FormC, FormD in that order?

I would say yes but is this preservation of the order of the remaining items
when an item is deleted (from anywhere in the collection) documented
An array does not change because it doesn't gain or lose elements unless
it is redim'd. It them changes unless Redim Preserve is used.

Yes but what I meant is that you have manual control of array indexing in
that you can remove an element by manually shifting the remaining elements
making sure that the indexing follows your rules.

Jon
 
A

Arvin Meyer [MVP]

Jon Lewis @btinternet.com> said:
Yes but what I meant is that you have manual control of array indexing in
that you can remove an element by manually shifting the remaining elements
making sure that the indexing follows your rules.

Not really. If you have 3 forms and open them in order.

Form1 (0)
Form2 (1)
Form3 (2)

Now close Form2, and what's left is:

Form1 (0)
Form3 (1)

Now close Form1:

Form3 (0)

Now opem Form2:

Form3 (0)
Form2 (1)

Get it?
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access
Co-author: "Access 2010 Solutions", published by Wiley
 
L

Larry Linson

I'm not sure what is confusing you about Arvin's responses. He's told you
the answer and given you a full example. Perhaps if you told us how you
expect to use that information, someone could suggest a different approach
that would be easier to implement and a description that would be easier for
you to follow.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top