If you are calling a form from another form the calling form will always remain in memory until the called form is closed. You can hide the calling form but that is it.
As ALWAYS there is more than one way to "skin a cat" in MS Access, especially in VBA. Here are some popular and not-so-popular techniques. (Not in any specific order.)
(1)
Using Global Variables.
Define a Public variable in a module (not the Form module). Have the First form set the variable. Then have the Second Form read the variable.
(2)
Use the OpenArgs Property.
Typically in code you would open a form using the DoCmd.OpenForm method. I believe that the last arguement for this method is the OpenArgs string. Which allows you to send a string to the form you are calling.
This is very easy for one value to be passed.
Otherwise you would need to concatenate several values together with a delimiter. Pass the arguement. Then the opening form would parse out the arguements and do its data type conversions as neccessary.
(3)
Hiding Then Closing First Form.
Have the first form set its Visible Property to False. This will hide it, but not close it. Then open the second form. The second form can now reference the first form directly, because it is still open. Once it gets the values, the second form can run a {DoCmd.Close acForm, "First Form Name"} command to close the first form.
(4)
Using Tables (Local Tables)
Create a working table that is local to your application. (Meaning its not in the back-end database of a split database.) Have the first form append values to the working table. Then have the second form read the values from the working table.
Hope this helps.
I've used all of these techniques at one time or another...really depending on what was needed at the time.
I was looking at the openargs function. I know how to open the form with the openargs command at the end, however I am not sure how to use that information to fill in the required field in the form being opened. Here is my situation:
On the first form I have a value in a field called Transmix. This value is saved to a table. I would use this table to pull the needed information into the second form but the second form is pulling information from other tables and other orders, I have no way of using query critera to seperate out just the transmix amount. The transmix field is an unusual happening and is only one ticket out of 4 or more being looked at in the second form.
On the second form I have a field called transmix volume.
I open the second form from an on click event button on the first form. I already have "form1;transmix" set as an opneing argument docmd.opneform of the on click.
Where I am running into problems is how do I use or call the opening args into the appriate field on the second form. I know I need to use a LEN argument however I have not worked with openargs function at all and have no idea where to begin and help file is not helping (big supprise).
If you can give me some advice or point me to a tutorial on openargs, I sure would appreicate it. Thanks
RBE RBE
Let's say you're passing the Record ID from the first form into the second form.
Typically, you can simply use Val(OpenArgs) to convert the string value to a numeric value. There are other data type conversion functions like CStr(), CDbl(), CInt(), etc. etc. etc.
Also look up the Nz() function. This allows you to convert a Null to another value, or to zero by default.
example:
A Record ID (long) was passed through the OpenArgs. Since it is a String it needs to be converted to Long, but it might also be a Null value. So, remembering back in high school compound functions....we can combine several functions together.
=CLng(Nz(OpenArgs,0))
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.