How can I return a value or a set of values from a Modally loaded form?
Any help will be highly appreciated.
(I don't want to use global Variables)
Printable View
How can I return a value or a set of values from a Modally loaded form?
Any help will be highly appreciated.
(I don't want to use global Variables)
Firstly, the variable must be declared public on the form. You can reference this variable using the form name on which it resides.
Ex.
On form2
Public strYourString as string
strYourString = "A form2 variable"
on form1 you can use this variable like this
text1 = form2.strYourString
'text1 will now show "A form2 variable"
David Paulson
write this in the form you want to return a value:
property get MyProp() as string
MyProp = "My Returned Value" 'set your value
'here
End property
and then you can access it from another form by using:
MyReturnedValue=form2.MyProp (form2 is the form that returns the value)
----------
The @host is everywhere!
----------
'Here another way to do it (retrieve a value from your modally loaded form)
'two forms: form1 and form2
'on each, one commandbutton (= Command1)
'form1 code
option Explicit
Dim withevents f as Form2
private Sub Command1_Click()
set f = new Form2
Load f
f.Show vbModal
set f = nothing
End Sub
private Sub f_myevent(byval strMystring as string)
MsgBox strMystring
End Sub
'-----------------
'form2 code
option Explicit
Event myevent(byval strMystring as string)
private Sub Command1_Click()
RaiseEvent myevent("ThisIsMyStringValue")
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
In From 1 - Parent form:
Private Sub cmdCallChild_Click()
dim strReturn
call frmChild.ShowForm(strReturn)
End Sub
In form 2 - Child form:
Public Sub ShowForm(ByRef strReturn as String)
Me.Show
'Return value after closing
strReturn ="Test string from the child form."
End Sub
Regards,
Michi
MCSE, MCDBA
hi,
More simple is you can use the "Tag" property of Form.
'in the Form1
form2.show vbModal
strVariable=Form2.Tag
'in the form2 u can store value
form2.Tag="Return Message"
regards,
Govind