Click to See Complete Forum and Search --> : How to return value from a Form
waqas_hussain
July 7th, 2001, 10:43 PM
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)
d.paulson
July 7th, 2001, 11:06 PM
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
deghost
July 8th, 2001, 04:09 PM
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!
----------
Cimperiali
July 9th, 2001, 10:03 AM
'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.
michi
July 9th, 2001, 11:36 AM
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
govindsharma
July 31st, 2001, 07:01 AM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.