Open form with and argument

Kenln

Registered User.
Local time
Today, 13:16
Joined
Oct 11, 2006
Messages
551
I understand how to call a function or subroutine with an argument.

Call Sub_Name ("argument")

How do I open a form with an argument. I have a form that I would like to open with different record source, hide or display different columns, change the caption of a few labels etc... The best way I can think of doing this is to open it with an argument since I am changing more than the record source.

Thank you in advance,
 
Last edited:
'DoCmd.OpenForm' allows you to either use a pre-specified filter or a where clause.
 
the last portion of the DoCmd.OpenForm command is OpenArgs.
Code:
DoCmd.OpenForm "formName",acNormal,,,,,"My Argument"
You reference those arguments from the opened form using Me.OpenArgs
 
That only get me as far as a filter or where clause. I am changing the actual record source object (one table vrs another), additionally I change several label.captions.

I don't think the DoCmd.OpenForm will do this for me. If I could open the form with an argument I could test for the argument value and change things in the sub Form_Load().
 
Works Great!!

Too bad you can't pass several arguments over.

Thank you,
 
Actually....

You actually can with a little bit of extra code. When you use the docmd.openform and pass the arguments, simply concatenate them all into one string with unique dividers between them, ie "arguement1;argument2;argument3". Then, when you reference the me.openargs in the loading procedure to the form, you simply pull the string apart into your seperate arguments via the instr and mid methods. instr will return the position in the string of a particular character ie ";". Then you use the mid method to pull the values out, using the position of the ";" as a marker for the starts/ends of the values.
 
Sorry, I should have thought of that myself.

Thanks
 
If you're going to have more than a couple of arguments, you may find the Split function easier to get them out with than the InStr & Mid functions.
 
Thanks Paul,

Great help
 
Last edited:

Users who are viewing this thread

Back
Top Bottom