dbTalk Databases Forums  

Opening a Form

comp.databases.ms-access comp.databases.ms-access


Discuss Opening a Form in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mat
 
Posts: n/a

Default Opening a Form - 03-10-2010 , 06:28 PM






Hi all,

When opening a form there appears to me to be two ways to do so:

Option 1:
docmd.openform "Form1"

Option 2:
dim frm as Form
set frm = New Form1


OK so my question is: Can I combine the two options?
dim frm as Form
docmd.OpenForm strFormName
set frm = Forms(Forms.Count-1) 'the newest form created

The reason I don't think I can is because when I use option1 I can
click design view on the form but when I use option 2 design view is
disabled.

I want to combine the two options because using option 1 I can open a
form via a string whereas using option 2 I have to specify which form
I want to create an instance of.

Reply With Quote
  #2  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Opening a Form - 03-10-2010 , 11:43 PM






Mat wrote:
Quote:
When opening a form there appears to me to be two ways to do so:

Option 1:
docmd.openform "Form1"

Option 2:
dim frm as Form
set frm = New Form1

OK so my question is: Can I combine the two options?
dim frm as Form
docmd.OpenForm strFormName
set frm = Forms(Forms.Count-1) 'the newest form created

The reason I don't think I can is because when I use option1 I can
click design view on the form but when I use option 2 design view is
disabled.

I want to combine the two options because using option 1 I can open a
form via a string whereas using option 2 I have to specify which form
I want to create an instance of.

Couple of things:
Option 2 needs to use:
set frm = New Form_Form1
and there is no guarantee that Forms(Forms.Count-1)
actually is the newest form created.

Note that unless you want to open multiple instances of the
same form, I know of no good reason to use:
Set frm = New Form_...
but then don't forget to follow that with:
frm.Visible = True
if you want to see the newly opened instance of the form.

If you use OpenForm then you can use:
Set frm = Forms("Form1")
to refer to the form via a string.

When you use:
Set frm = New Form_Form1
the form will close when the procedure exits because the
object variable, frm, will go out of scope. To prevent that
you should create and manage your own collection of the open
instances of the form, kind of like the Forms collection.
For details about that, see:
http://allenbrowne.com/ser-35.html

--
Marsh

Reply With Quote
  #3  
Old   
Mat
 
Posts: n/a

Default Re: Opening a Form - 03-11-2010 , 12:15 AM



Thanks for the corrections I was sloppy with the notation.

Quote:
and there is no guarantee that Forms(Forms.Count-1)
I didn't know that. That gives me something to test, because I might
need to search through the collection for the right form.

The reason is that my collection of forms is not the same form.
Depending on what is clicked one of several forms will open and get
stored in the collection. This has led me to create a select case
statement based upon a string.
select strFormName
case "A":
set frm = new Form_Form1
case "B":
set frm = new Form_Form2
'add to the collection to preserve it

However this means updating the case statement with every new form I
wish to create.

I was hoping to avoid the select case statement by opening the form
using the docmd.openform statement and pass the strFormName to that
then point to it then add it to the collection.

Reply With Quote
  #4  
Old   
Allen Browne
 
Posts: n/a

Default Re: Opening a Form - 03-11-2010 , 09:36 AM



Mat, if you don't need to have multiple instances of a form open, why do you
need your own collection?

Access maintains a collection of open forms. It's called Forms. You can
locate a form if you know its name with:
Forms(strFormName)

--
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.


"Mat" <matthew.kay (AT) optusnet (DOT) com.au> wrote

Quote:
Thanks for the corrections I was sloppy with the notation.

and there is no guarantee that Forms(Forms.Count-1)

I didn't know that. That gives me something to test, because I might
need to search through the collection for the right form.

The reason is that my collection of forms is not the same form.
Depending on what is clicked one of several forms will open and get
stored in the collection. This has led me to create a select case
statement based upon a string.
select strFormName
case "A":
set frm = new Form_Form1
case "B":
set frm = new Form_Form2
'add to the collection to preserve it

However this means updating the case statement with every new form I
wish to create.

I was hoping to avoid the select case statement by opening the form
using the docmd.openform statement and pass the strFormName to that
then point to it then add it to the collection.

Reply With Quote
  #5  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Opening a Form - 03-11-2010 , 11:36 AM



Mat wrote:

Quote:
Thanks for the corrections I was sloppy with the notation.

and there is no guarantee that Forms(Forms.Count-1)

I didn't know that. That gives me something to test, because I might
need to search through the collection for the right form.

The reason is that my collection of forms is not the same form.
Depending on what is clicked one of several forms will open and get
stored in the collection. This has led me to create a select case
statement based upon a string.
select strFormName
case "A":
set frm = new Form_Form1
case "B":
set frm = new Form_Form2
'add to the collection to preserve it

However this means updating the case statement with every new form I
wish to create.

I was hoping to avoid the select case statement by opening the form
using the docmd.openform statement and pass the strFormName to that
then point to it then add it to the collection.

I never heard of a way to create a class instance without
using the literal class name with New.

I think it would be easier to have a separate procedure with
its own collection for each form with multiple instances.
OTOH, its your code and if you prefer combining all of them
in a single collection, who am I to object. Either way, I
believe you will need to add/modify some code for each form.

--
Marsh

Reply With Quote
  #6  
Old   
Mat
 
Posts: n/a

Default Re: Opening a Form - 03-11-2010 , 07:55 PM



Quote:
Mat, if you don't need to have multiple instances of a form open, why do you need your own collection?
My situation is multiple instances of multiple forms. In fact I
decided to open every form as an instance of that form. It is probably
pushing access to far?

Quote:
Access maintains a collection of open forms. It's called Forms. You can locate a form if you know its name with:
Forms(strFormName)
My understanding is that one should create and use their own
collection when working with instances of a form. When you create a
form in a procedure it gets added to the Forms collection for that
temporary time and removed when it goes out of scope so you pass the
instance of the form to a collection to keep it.

Quote:
I never heard of a way to create a class instance without using the literal class name with New
It is a bit irritating there isn't a function, that you can pass a
parameter to, to open a form.

Quote:
think it would be easier to have a separate procedure with its own collection for each form with multiple instances.
OTOH, its your code and if you prefer combining all of them in a single collection, who am I to object. Either way, I
believe you will need to add/modify some code for each form.
I was kind of experimenting. Either solution has the same core problem
of when you create a new form you have to create new code to manage
it.

Thanks for the replies to date. They are much appreciated.

Reply With Quote
  #7  
Old   
Allen Browne
 
Posts: n/a

Default Re: Opening a Form - 03-11-2010 , 10:02 PM



Okay: if you are working with multiple instances, then the Forms collection
is not adequate for distinguishing between them, so you do need your own
collection.

The need for multiple instances is pretty rare. Very few of my production
databases use them, so I wouldn't consider it an ideal way to handle forms
in general. Further, my experiments with multiple instances of reports has
not been too productive, so I don't use that at all.

It would be handy if we could use a variable name with the New keywords for
the Form_Form1 thingy, but I never followed that through either.

--
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.


"Mat" <matthew.kay (AT) optusnet (DOT) com.au> wrote

Quote:
Mat, if you don't need to have multiple instances of a form open, why do
you need your own collection?

My situation is multiple instances of multiple forms. In fact I
decided to open every form as an instance of that form. It is probably
pushing access to far?

Access maintains a collection of open forms. It's called Forms. You can
locate a form if you know its name with:
Forms(strFormName)

My understanding is that one should create and use their own
collection when working with instances of a form. When you create a
form in a procedure it gets added to the Forms collection for that
temporary time and removed when it goes out of scope so you pass the
instance of the form to a collection to keep it.

I never heard of a way to create a class instance without using the
literal class name with New

It is a bit irritating there isn't a function, that you can pass a
parameter to, to open a form.

think it would be easier to have a separate procedure with its own
collection for each form with multiple instances.
OTOH, its your code and if you prefer combining all of them in a single
collection, who am I to object. Either way, I
believe you will need to add/modify some code for each form.

I was kind of experimenting. Either solution has the same core problem
of when you create a new form you have to create new code to manage
it.

Thanks for the replies to date. They are much appreciated.

Reply With Quote
  #8  
Old   
Mat
 
Posts: n/a

Default Re: Opening a Form - 03-11-2010 , 10:49 PM



Quote:
Okay: if you are working with multiple instances, then the Forms collection
is not adequate for distinguishing between them, so you do need your own
collection.

The need for multiple instances is pretty rare. Very few of my production
databases use them, so I wouldn't consider it an ideal way to handle forms
in general. Further, my experiments with multiple instances of reports has
not been too productive, so I don't use that at all.

It would be handy if we could use a variable name with the New keywords for
the Form_Form1 thingy, but I never followed that through either.
I agree the need is rare, it began with experimenting with collections
and so on. Right now I enjoy the feel the user gets from having say a
project database and two different projects open at once in two
instances of the project form. I know they could both be open in one
form ....

I am pretty certain that I will end up using the docmd method of
opening forms in the end. I generally prefer to work with access than
fight against what it is offering for to long.

Reply With Quote
  #9  
Old   
hbinc
 
Posts: n/a

Default Re: Opening a Form - 03-12-2010 , 05:02 PM



On Mar 11, 6:15*am, Mat <matthew.... (AT) optusnet (DOT) com.au> wrote:
Quote:
Thanks for the corrections I was sloppy with the notation.

and there is no guarantee that Forms(Forms.Count-1)

I didn't know that. That gives me something to test, because I might
need to search through the collection for the right form.

The reason is that my collection of forms is not the same form.
Depending on what is clicked one of several forms will open and get
stored in the collection. This has led me to create a select case
statement based upon a string.
select strFormName
case "A":
*set frm = new Form_Form1
case "B":
set frm = new Form_Form2
'add to the collection to preserve it

However this means updating the case statement with every new form I
wish to create.

I was hoping to avoid the select case statement by opening the form
using the docmd.openform statement and pass the strFormName to that
then point to it then add it to the collection.
Hi Mat,

I have been puzzling on your problem for som time to try to understand
what you are aiming for.
I think I miss some point, because I can not translate it to some
practical situation that I use.
Why you want or need instances of a form, while you can open a form
with DoCmd.OpenForm?


HBInc.

Reply With Quote
  #10  
Old   
Mat
 
Posts: n/a

Default Re: Opening a Form - 03-12-2010 , 08:23 PM



Quote:
Hi Mat,

I have been puzzling on your problem for som time to try to understand
what you are aiming for.
I think I miss some point, because I can not translate it to some
practical situation that I use.
Why you want or need instances of a form, while you can open a form
with DoCmd.OpenForm?

HBInc.
Honest answer. All the 'books' talk about opening instances of a form.
I don't think it is necessary to do this for nearly any application
other than developer preference. Anyone else got a good reason for
opening multiple instances of a form?

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.