oop Programing quesiton....

J

John 3:16

Hello....
Not sure if this is the right newsgroup for this or not.
I'm trying to learn to migrate to using classes and oop.

Instead of referencing a form like

dim i as integer
i = Forms![MyForm].form.tbMyTextBox
docmd.openform("Form2")
Forms![Form2].form.inputparameters = i

How can I build and use a class like.....

dim a as new addr 'addr being a class
a.property1 = somevalue
docmd.openform("Form2")
Forms![Form2].form.inputparameters = a.property1

My problem is maintaing scope from form to form for the class.

Hopefully this description is clear enough for someone to shed
some light on this or point me in the right direction.

thanks,
bob mcclellan
 
V

Vadim Rapp

J> How can I build and use a class like.....

J> dim a as new addr 'addr being a class
J> a.property1 = somevalue
J> docmd.openform("Form2")
J> Forms![Form2].form.inputparameters = a.property1

J> My problem is maintaing scope from form to form for the class.

This can be accomplished by using Public Property in the form's code.


Vadim Rapp
 
J

John 3:16

Thanks for the reply Vadim
The Class property is declared as Public.
...but when you instanstiate a new class object, then
open the next form, the class is out of scope, so it's properties are out
of scope.
 
V

Vadim Rapp

Hello John:
You wrote on Thu, 8 Jun 2006 14:23:34 -0400:

J> Thanks for the reply Vadim
J> The Class property is declared as Public.
J> ..but when you instanstiate a new class object, then
J> open the next form, the class is out of scope, so it's properties are
J> out of scope.

Sorry, don't quite understand. In Access, you can't have more than one
instance of the same form. So you refer as forms!form1.myproperty=1.

Vadim
 
R

Robert Morley

Actually, in Access 2000 and beyond (and maybe 95/97, I forget), you most
certainly CAN have more than one instance of a form. You have to forego
using DoCmd.OpenForm, however, and instantiate the form directly. The code
below is vastly simplified, but would happily open two instances of the same
form.

Dim f1 As New MyForm
Dim f2 As New MyForm

f1.Visible = True
f1.SomeValue = "Form1"
f2.Visible = True
f2.SomeValue = "Form2"


Or in a class-based situation, you would simply instantiate the one form
with

Dim f1 As New MyForm
'Or more properly...
'Dim f1 As MyForm
'Set f1 As New MyForm
'... do stuff
'Set f1 = Nothing

Each instance of the class would then have its own instance of the form, f1
(which you can then echo out of the class as a property, or do whatever you
want to do with it).


Rob
 
V

Vadim Rapp

Hello Robert:
You wrote on Fri, 9 Jun 2006 14:37:53 -0400:

RM> Actually, in Access 2000 and beyond (and maybe 95/97, I forget), you
RM> most certainly CAN have more than one instance of a form.

Indeed, I did not even know. Cool. Then what's the problem.

f1.Visible = True
f2.Visible = True

f1.p1 = 3
f2.p1 = 4

Vadim
 

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