-
Solved: Other than using a "Public" variable....
Other than using a public variable, is there any way to conveniently "pass" a value from one form to another? For example:
I am using form-1 for working with a table. Periodically, I need some information not available on the form or table. The data isn't something that can be related to the original form. I have a command button that loads and shows a form-2 which allows me to calculate another piece of information.
- I know I can just move the data into a "public" variable and close the form-2
- I know I can use form-1.txtbox.value = new value
What I would like to do is create a function to get the data such as:
myData = getData() and have getData() load the form and return the value....
Just a question
-
Pass it in the OpenArgs parameter of the OpenForm method.
-
Xcav8r
I want to go the other way around.
Form-1 is already open and being used. From it, I open form-2 without any arguements and want to send a piece of information BACK to form-1 which is already open.
-
It sounds like you've already got a handle on how it can be done. Is putting it into a function where you're having trouble?
-
Actually, yes. I try to stay away from "public" variables as much as possible (just a personal thing) and I don't always have the same "calling" form.
Nothing wrong with what I am doing, just thought there might be a different and/or better way.
-
If you need the form to reference a value that doesn't need its own control to edit or display, you can always wrap the value in a Private module-level variable and create a user-defined property as the interface.
Let's say Form-1 is set to receive the new data (in this case, a String), and has a button named Button1 that displays the String in a MessageBox. We could make a user-defined property named "Stuff" and code the form module like so:
[VBA]
Option Explicit
Private strStuff as String
Property Let Stuff(s as String)
strStuff = s
End Property
Property Get Stuff() as String
Stuff = strStuff
End Property
Private Sub Button1_Click()
MsgBox Me.Stuff
End Sub
[/VBA]
Form-2 has a textbox named TBox1 and a button named Button2, and is set to pass the value of Tbox1 to Form-1 when the button is clicked.
[VBA]
Private Sub Button2_Click()
Forms("Form-1").Stuff = Tbox1.Value
End Sub
[/VBA]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules