Multiple Form Instances - Add new record

M

Matthew Pfluger

Can I open a new instance of a form and move it to a new record? If so,
could any problems arise if a user opens two instances in this way (set to
new records)?

Thanks,
Matthew Pfluger
 
J

Jeff Boyce

Matthew

Perhaps you work with a better-trained, more intelligent group of users.
The folks I build applications for can't be troubled with figuring out or
remembering which instance of a form they are working in, so I typically
build their applications so they can focus on one thing at a time.

What business need will you be able to address/answer by having multiple
instances of the same form...?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
M

Matthew Pfluger

I am a Mechanical Engineer building a Quotes Database for a group of more
Mechanical Engineers, and my coworkers like to look at details for more than
one part/quote/vendor at a time. Also, they don't need to know what instance
they are in; they just like the flexibility of having multiple "Details"
forms open at once.

I did end up figuring out a way to do this. Once the new instance of the
form is open and active, I just call the following command:
Docmd.GoToRecord ,,adNewRecord

Since I don't have to refer to the form by name, the code works with
multiple instances. Granted, there should not often be a case where someone
is entering more than one NEW quote at a time, but I like the flexibility of
multiple forms.

Thanks,
Matthew Pfluger
 
G

Graham Mandeno

Hi Matthew

You can create multiple instances of a form by creating Form class variables
and using the New keyword:

Dim f1 as Form, f2 as Form
Set f1 = New Form_Employees
f1.Filter = "EmployeeID=4"
f1.FilterOn = True
f1.Visible = True
Set f2 = New Form_Employees
f2.DataEntry = True
f2.Visible = True
....

The form will only exist for as long as the class variable is in scope, so
normally you would declare these at module level.

You don't have the luxury of passing arguments to the OpenForm method, but
you could declare an array of forms and write your own function to which you
can pass arguments in the same way you do for OpenForm. Of the top of my
head, the only features you couldn't implement would be WindowMode:=acDialog
and OpenArgs. Other properties such as Filter,
AllowAdditions/Edits/Deletions, DataEntry, Visible, Caption, etc could
easily be passed as arguments.
 
M

Matthew Pfluger

Yeah, multiple instances are great! I am a huge fan now. I'm using about 4
forms in this way with public forms collections. My "customers" (co-workers)
really like the feature, too.

The only strange behavior I've notice is that the Form_Close event doesn't
seem to run all the time. When an instance is open and I strike CTRL+W or
click the CLOSE (X) button, the Close event doesn't fire. This means that
the form doesn't run code to remove itself from the public collection, so it
remains in memory. I don't know how to get around this, but I'll keep trying.

I also discovered that a combo box that used another control in its
RowSource data query no longer functioned correctly. After a lot of work, I
ended up using a procedure that created a RecordSet, opened the RecordSet
based on another control in the instance, set the RecordSet results as the
ComboBox's Value List, and ended the procedure without closing the RecordSet.
Since this procedure can be called from the form's controls' events, I could
pass it variables within instances. Turned out pretty slick!

Thanks for all the ideas, MVPs. On this Thanksgiving, I'm thankful for your
help! :)

Matthew Pfluger


Graham Mandeno said:
Hi Matthew

You can create multiple instances of a form by creating Form class variables
and using the New keyword:

Dim f1 as Form, f2 as Form
Set f1 = New Form_Employees
f1.Filter = "EmployeeID=4"
f1.FilterOn = True
f1.Visible = True
Set f2 = New Form_Employees
f2.DataEntry = True
f2.Visible = True
....

The form will only exist for as long as the class variable is in scope, so
normally you would declare these at module level.

You don't have the luxury of passing arguments to the OpenForm method, but
you could declare an array of forms and write your own function to which you
can pass arguments in the same way you do for OpenForm. Of the top of my
head, the only features you couldn't implement would be WindowMode:=acDialog
and OpenArgs. Other properties such as Filter,
AllowAdditions/Edits/Deletions, DataEntry, Visible, Caption, etc could
easily be passed as arguments.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Matthew Pfluger said:
Can I open a new instance of a form and move it to a new record? If so,
could any problems arise if a user opens two instances in this way (set to
new records)?

Thanks,
Matthew Pfluger
 

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