OOP in Access ?

B

ByB

Hello,

I am working in an apàplication written in VBA and running in Access,
and I get some problems related to Object Programming. Can somebody
give me a hint in these questions :

I would like to give a Form 2 parameters when loading it. I tried with
OpenArgs, but did not find the way to pass it 2 parameters : I tried to
create a class which contains the two parameters, convert it to a
Variant by the mean of CVar() and pass it to
Application.DoCmd.OpenForm, but I get an error message about type of my
variable.

So I tried the following way (assuming that F_MyForm is the name of the
form I created) :
- Added a Let property to the F_MyForm objet (SetMyParameter)
- Dim f as F_MyForm
- Set f = New F_MyForm
- f.SetMyParameter = 12
- f. ???
This the point : I tried to find a method to call to open a form this
way, but did not find any (I have tried f.open, f.Activate, f.Show,
f.Display etc, but always got error message). So is there a way to open
a form when created this way ?


Thank you for your answers, or for telling me how to pass 2 parameters
to a form, even by the mean of OpenForm ...
 
G

George Nicholson

FYI:
Set f = Form_frmSolutions
DoCmd.OpenForm f.Name
Will actually open 2 instances of the same form (Forms.Count = 2.
Forms(0).Visible = False and Forms(1).Visible = True)

(where "Form_frmSolutions" is the exact name I see in the Project Explorer
under "Microsoft Office Access Class Objects" in the VBE)

At that point, the following should work:
f.SetMyParameter = 12
But it would only apply to the1st, hidden, instance.

In both cases the Form_Open and Form_Load events have come and gone. If you
need parameter values during Form_Open then either:
1) Pass them together via the OpenArgs argument (using a delimiter) and
parse OpenArgs to separate them again during Form_Open
or
2) create some Public variables (varFormArg1, varFormArg2) in a general
module and assign your arguments to them before DoCmd.OpenForm. The values
would then be available in Form_Open (and anywhere else in the app).

HTH,
 
B

ByB

Hello,

Thank your very much for your message.
I am very surprised that there is no way to open a form that was
created in the mémory of the computer with New ?

For the moment, I use the first solution you mentioned, with OpenArgs
ans a delimiter. But I find this solution not really OO oriented ...
:-(



Toujours très informé, George Nicholson affirme que
FYI:
Set f = Form_frmSolutions
DoCmd.OpenForm f.Name
Will actually open 2 instances of the same form (Forms.Count = 2.
Forms(0).Visible = False and Forms(1).Visible = True)
(where "Form_frmSolutions" is the exact name I see in the Project Explorer
under "Microsoft Office Access Class Objects" in the VBE)
At that point, the following should work:
f.SetMyParameter = 12
But it would only apply to the1st, hidden, instance.
In both cases the Form_Open and Form_Load events have come and gone. If you
need parameter values during Form_Open then either:
1) Pass them together via the OpenArgs argument (using a delimiter) and
parse OpenArgs to separate them again during Form_Open
or
2) create some Public variables (varFormArg1, varFormArg2) in a general
module and assign your arguments to them before DoCmd.OpenForm. The values
would then be available in Form_Open (and anywhere else in the app).


ByB said:
Hello,

I am working in an apàplication written in VBA and running in Access, and I
get some problems related to Object Programming. Can somebody give me a
hint in these questions :

I would like to give a Form 2 parameters when loading it. I tried with
OpenArgs, but did not find the way to pass it 2 parameters : I tried to
create a class which contains the two parameters, convert it to a Variant
by the mean of CVar() and pass it to Application.DoCmd.OpenForm, but I get
an error message about type of my variable.

So I tried the following way (assuming that F_MyForm is the name of the
form I created) :
- Added a Let property to the F_MyForm objet (SetMyParameter)
- Dim f as F_MyForm
- Set f = New F_MyForm
- f.SetMyParameter = 12
- f. ???
This the point : I tried to find a method to call to open a form this way,
but did not find any (I have tried f.open, f.Activate, f.Show, f.Display
etc, but always got error message). So is there a way to open a form when
created this way ?


Thank you for your answers, or for telling me how to pass 2 parameters to a
form, even by the mean of OpenForm ...




-- Toutes les fois qu'on a l'occasion de réaliser une métaphore, doit-on
hésiter un seul instant ?
[Alphonse Allais]
 
J

Jeff Hopper

Sadly, while VBA and the Office APIs do use "objects," they are far from
being object oriented. George's suggestions are, unfortunately, the best
ones, given the platform.

ByB said:
Hello,

Thank your very much for your message.
I am very surprised that there is no way to open a form that was created
in the mémory of the computer with New ?

For the moment, I use the first solution you mentioned, with OpenArgs ans
a delimiter. But I find this solution not really OO oriented ... :-(



Toujours très informé, George Nicholson affirme que
FYI:
Set f = Form_frmSolutions
DoCmd.OpenForm f.Name
Will actually open 2 instances of the same form (Forms.Count = 2.
Forms(0).Visible = False and Forms(1).Visible = True)
(where "Form_frmSolutions" is the exact name I see in the Project
Explorer under "Microsoft Office Access Class Objects" in the VBE)
At that point, the following should work:
f.SetMyParameter = 12
But it would only apply to the1st, hidden, instance.
In both cases the Form_Open and Form_Load events have come and gone. If
you need parameter values during Form_Open then either:
1) Pass them together via the OpenArgs argument (using a delimiter)
and parse OpenArgs to separate them again during Form_Open
or
2) create some Public variables (varFormArg1, varFormArg2) in a
general module and assign your arguments to them before DoCmd.OpenForm.
The values would then be available in Form_Open (and anywhere else in the
app).


ByB said:
Hello,

I am working in an apàplication written in VBA and running in Access,
and I get some problems related to Object Programming. Can somebody give
me a hint in these questions :

I would like to give a Form 2 parameters when loading it. I tried with
OpenArgs, but did not find the way to pass it 2 parameters : I tried to
create a class which contains the two parameters, convert it to a
Variant by the mean of CVar() and pass it to Application.DoCmd.OpenForm,
but I get an error message about type of my variable.

So I tried the following way (assuming that F_MyForm is the name of the
form I created) :
- Added a Let property to the F_MyForm objet (SetMyParameter)
- Dim f as F_MyForm
- Set f = New F_MyForm
- f.SetMyParameter = 12
- f. ???
This the point : I tried to find a method to call to open a form this
way, but did not find any (I have tried f.open, f.Activate, f.Show,
f.Display etc, but always got error message). So is there a way to open
a form when created this way ?


Thank you for your answers, or for telling me how to pass 2 parameters
to a form, even by the mean of OpenForm ...




-- Toutes les fois qu'on a l'occasion de réaliser une métaphore, doit-on
hésiter un seul instant ?
[Alphonse Allais]
 

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