multiple open args

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

Guest

I am using a DoCmd.open form command with an opening argument. how do i set
it so that i can use multiple open arguments. for example, i want the
dateofvisit, and SSN to be teh open args because they are both primary keys.
i would also like to use lastname as an openarg if it is possible to use 3.

thank you
 
Just build an OpenArgs string that contains all the individual parts
separated by a delimiter (often, ; or | is used).

Then, in the form, create a module-level global variant variable and then
use Split function in the form's Load event to parse the OpenArgs string:

Private varOpenArgsArray As Variant

Private Sub Form_Load()
varOpenArgsArray = Split(Me.OpenArgs, "|")
' then have code that uses the different values in the array
End Sub
 
Why all with open args?

If it's a bound form and all tree fields are available, you can do it with a
simple where clause

docmd.openform "formname",,,"dateofvisit=#" & strdat & "# AND SSN=" &
intSSN & " AND lastname ='" & strLastname & "'"
 
Ken,
I am unsure of what you mean by module-level global variant variable .

could you explain this please. also, how are the first and second etc open
args differentiated between each otehr?

thank you
russ
 
By Module-level Global variant he means the following line:

Private varOpenArgsArray As Variant

Global: this variable can be accessed in all your procedures and functions
in your form or module
Module-Level: "Private": this variable will not be available outside your
form or module

Why do you want to use open args? Can't you use the where clause in the
docmd.openform procedure?

Kind regards
 
By Module-level Global variant he means the following line:

Private varOpenArgsArray As Variant

Global: this variable can be accessed in all your procedures and functions
in your form or module
Module-Level: "Private": this variable will not be available outside your
form or module

Why do you want to use open args? Can't you use the where clause in the
docmd.openform procedure?

Kind regards
 
Damiaan,
thank you for your help.
i dont think i can use the where clause becasue i not only want to review
the current records, but i also want to add records. so when i open the form
i want ssn and lastname to the open args, so when i add a new record they
will become the filled out automatically. i dont want to have to type these
in if i add a new record.

as far as the code goes, i am unsure of how the different openargs are
referred to after they are split.
i have the folliwng code:
Me.SSN = Me.OpenArgs
how do i change this to refer to the openargs after it is plit and add teh
lastname part of the code?

thank you very much,
russ
 
As Damiaan noted, the first line where the varOpenArgsArray is declared is
the global variable. It goes above all the procedures in the module.

Damiaan's point about whether you could use the WhereCondition argument of
the DoCmd.OpenForm action might be another solution for you. It's not clear
what you will do with the values that you pass in the open args argument.

I don't understand what you mean by "how are the first and second etc open
args differentiated between each otehr?" What I posted allows you to
separate the various strings into separate memory locations within the
varOpenArgsArray variable, and then you can use that array variable to
choose which one you want.
--

Ken Snell
<MS ACCESS MVP>
 
as far as the code goes, i am unsure of how the different openargs are
referred to after they are split.
i have the folliwng code:
Me.SSN = Me.OpenArgs
how do i change this to refer to the openargs after it is plit and add teh
lastname part of the code?

if you call the form with

docmd.openforms "myform",openargs:="test1|ssnno|some more text"

and then in the form_open event om myform:

'split the openargs variable into an array using the | sign as delimeter
myArray = split(me.openargs, "|")

variable1 = myarray(1)
ssnnumber = myarray(2)
variable 3 = myarray(3)

kind regards
 
Ken and Damiaan,
i figured it out, i could figure out the following:
Me.SSN = varOpenArgsArray(0)
Me.LastName = varOpenArgsArray(1)

all set now.
thank you very much for all of your time and help, i appreciate it.
russ
 
Back
Top