Best method to pass values between forms (1 Viewer)

DMerchen

Registered User.
Local time
Today, 12:54
Joined
Sep 9, 2008
Messages
94
What is the best method to pass a value from one form to another when I open the new from from a button click? I have a lot of the information I need on one form, and I believe I could load those into variables and then pass them into the new form from those variables. But, is there a better method? Do I make a module with all of my variables I can then pull from when the new form opens?
Any help is greatly appreciated!!
 

Minty

AWF VIP
Local time
Today, 19:54
Joined
Jul 26, 2013
Messages
10,382
If you need a lot of "duplicate" information between two different forms, you may be going about things in a bit of an inefficient way.

Can you describe the purpose of your original form, and the form it opens?
 

DMerchen

Registered User.
Local time
Today, 12:54
Joined
Sep 9, 2008
Messages
94
Thanks for your inquiry. I have a form which has a lot of information from a purchase order. Items such as PO, Part#, Description, Customer, Customer PO, etc. I want to open a separate form for shipments and log a shipment against this Purchase order. A lot of the information is on this shipping form too so I want to copy information over so the user isn't retyping information. Unfortunately this is all coming over from Excel and they want me to develop the database using the same tables.Trying to navigate through this as painless as possible.

Thanks
 

Minty

AWF VIP
Local time
Today, 19:54
Joined
Jul 26, 2013
Messages
10,382
You may be able to simply link the PO information into your shipping information, if the shipping address is in the PO you shouldn't need to store it again.

If it's to store as a possibly different shipping address then you could insert the data using a query and then open the form on the new record just created.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:54
Joined
Feb 28, 2001
Messages
27,454
A few methods exist to allow this. I'll summarize because you can do lookups via web or this forum's search feature. You can decide which, if any, appeal to you.

1. You can write some VBA behind the first form to create TempVars (temporary memory-resident variables) to store what you need. Though you WILL need to clean up after you are done so that the next activity from that form doesn't have "leftovers." The second form could then look for the TempVars and if it finds them, it would know to load from them.

2. It is possible to declare a general module that has some Public variables in it that would persist pretty well, particularly if you had some common code routines that would be callable from any form. Then any Publics that you might have would be readable from other forms. Again, be sure to clean up.

3. It is possible to "know" that you are about to do something involving shipping and just pre-create a partial shipping record with the data from the first form, then using the form wizard to show you how to open the shipping form to a specific record (the one that you just created).

4. You can use the "OpenArgs" feature when opening the 2nd form to tell it that it was called in a specific way - so that it can just "read" the data from the controls of the first form. But if the 2nd form was opened directly, the OpenArgs value would be blank (by default) and your form could know that it didn't have anything to read. (You would make this decision in the 2nd form's Form_Load event routine.

#1 and #2 would probably require a flag (as TempVars or in a general module declaration area) to be reset by the 2nd form so that you would know if you had already used the data currently in the variables.

#3 and #4 would require the 2nd form to have enough smarts to detect how it was launched based on the OpenArgs value or the record currently loaded with the form. The latter case might include a flag in the record showing that it is complete or not so that you know to that the record is ready to be saved.

Just some ideas to bounce around. There are many ways to skin this cat {MEEOOOWRRRR!} and I'm not averse to any of them in the right circumstances.
 

DMerchen

Registered User.
Local time
Today, 12:54
Joined
Sep 9, 2008
Messages
94
Thank you for your responses. I knew there would certainly be different methods to accomplish this task. Now, to go try them out!! Thanks everyone!
 

Cronk

Registered User.
Local time
Tomorrow, 04:54
Joined
Jul 4, 2013
Messages
2,774
Why not display the PO information in a linked subform of the shipping form rather than displaying the PO info in presumably unbound controls.
 

Users who are viewing this thread

Top Bottom