form opening arguments

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to pass more than one argument to a form via the

DoCmd.OpenForm "MyForm",,,,,,MyArgument

routine?
Thanks
 
As much as I know, you can't pass more the one argument.
Instead you can create as many global variables that you need, before
opening the form assign the values to this variables, and you can use them
anywhere else in he DB, its just the same as sending few arguments to the
next form.
Just don't forget to create them in a module.
 
Great idea!!
--
sam


Ofer said:
As much as I know, you can't pass more the one argument.
Instead you can create as many global variables that you need, before
opening the form assign the values to this variables, and you can use them
anywhere else in he DB, its just the same as sending few arguments to the
next form.
Just don't forget to create them in a module.
 
You can, but then you'd have to parse the passed fields. I wasted a lot of
time doing that, early on.

You're probably much better off creating public properties and functions or
subs in the form you want to pass things to, and invoking them from the
calling form:

DoCmd.OpenForm "fzzDBCompare"
Forms!fzzDBCompare.StuffID "From", Me.DBId & ""

invokes the public function (or sub) StuffID in the form fzzDBCompare, and
passes the values "From" and Me.DBId to it. That function (or sub) will do
whatever you told it to do in the fzzDBCompare form, including finding the
first record where the field "From" equals me.DBId. (Assuming the function
or sub does that, of course.)

I'm frankly ashamed that it took me as long as it did to find this really
simple way of doing things, but I'm also kind of, well, call it irritated,
that it took me as long as it has to find it.

Like they say, everything's simple if you know the answer.

HTH,

Kevin
 
Is it possible to pass more than one argument to a form via the

DoCmd.OpenForm "MyForm",,,,,,MyArgument

routine?
Thanks

You can pass as many arguments as you like with OpenArgs, you just need
to separate them with a consistant character.

Here's how I call one of my reports:
MyDates = Me.txtFromDate & ";" & Me.txtToDate
DoCmd.OpenReport stDocName, acPreview, , , , MyDates


And here's part of the Open event code of the report:
Dim Args As Variant
If Not IsNull(Me.OpenArgs) Then
'-- Report is being opened from a form passing Dates
Args = Split(Me.OpenArgs, ";")
StartDate = Args(0)
EndDate = Args(1)
End If

HTH
 
Good suggestion. I'll try it.
--
sam


Kevin said:
You can, but then you'd have to parse the passed fields. I wasted a lot of
time doing that, early on.

You're probably much better off creating public properties and functions or
subs in the form you want to pass things to, and invoking them from the
calling form:

DoCmd.OpenForm "fzzDBCompare"
Forms!fzzDBCompare.StuffID "From", Me.DBId & ""

invokes the public function (or sub) StuffID in the form fzzDBCompare, and
passes the values "From" and Me.DBId to it. That function (or sub) will do
whatever you told it to do in the fzzDBCompare form, including finding the
first record where the field "From" equals me.DBId. (Assuming the function
or sub does that, of course.)

I'm frankly ashamed that it took me as long as it did to find this really
simple way of doing things, but I'm also kind of, well, call it irritated,
that it took me as long as it has to find it.

Like they say, everything's simple if you know the answer.

HTH,

Kevin
 
I hadn't seen the split function. Is that a custom function or part of MS
Access? Anybody have comments about which of the three techniques presented
here is faster?
 
I hadn't seen the split function. Is that a custom function or part of
MS Access? Anybody have comments about which of the three techniques
presented here is faster?

I have AccessXP (2K2) and it is a standard function. Have you tried your
help system for Split()?

I personally try and avoid global variables, but it is just a
personal preference. It contains things better for me.

HTH
 
I hadn't seen the split function. Is
that a custom function or part of MS
Access? Anybody have comments
about which of the three techniques
presented here is faster?

(1) Split is a built-in function of Access since at least Access 2000. If
you are using an older version, many people have posted Split code -- find
it by searching at http://groups.google.com.

(2) Any all-or-mostly-all-in-memory technique is going to be sufficiently
fast that, for something done as infrequently as forms are programmatically
opened, it would be a waste to try to determine which is faster.

For functions that might be done in "heavy calculations" in a loop within a
loop..., there might be some value in making that determination -- if the
loop counts are large numbers.

Larry Linson
Microsoft Access MVP
 
Global variables? That doesn't seem a very sound idea to me, though. It
creates an incrredibly complex state machine.

If you need to pass several values, that can be done in a comma
separated string, all in OpenArgs. You must then parse this in the Open
event handler of the form.
 
You could always send a comma delimited string and the use a function to
split the values.
 
Back
Top