Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass parameter between 2 forms?

Status
Not open for further replies.

VBNewBee

MIS
Jun 9, 2004
2
US
Hi,

I'm trying to pass the value of the selected ItemData from Listbox1 in Form A to Form B after the doubleclick event. My question is how can i pass the value to form B? Thank you in advance.
 
You can give the entire reference in form B, e.g. in the double click event in Form A, just put something like
FormB.whateveryouwant = ListBox1.List(someindex)
For this to work, the variable whateveryouwant must be publicly accessible.

You could also use a global variable. You can set
someglobal = ListBox1.List(someindex)
Then you can access someglobal from wherever you need it in Form B.

Hope that helps answer your question.
 
In the General Declarations of Form B, you can declare a Public variable (eg Public MyVar as string).

In your double-click event of the listbox, have something like this:

Code:
Load FormB
FormB.MyVar = Listbox1.Text
'//or whatever property you want to use
Code:
FormB.Show vbmodal
'//or remove the vbmodal if you want


hope this helps...

Adam
 
The best way is as follows:
In the General Declarations of Form B, you can declare a Private variable (eg private m_MyVar as string).

then and a property let procedure
Public Property Let MyVar(byval strData as string)

m_MyVar = strData

End Property

In your double-click event of the listbox, have something like this:
dim objFormB as FormB

Set objFormB = new FormB
Load objFormB
objFormB.MyVar = Listbox1.Text '//or whatever property you want to use
objFormB.Show vbmodal '//or remove the vbmodal if you want
'Get any info out, then clear the form from memory
UnLoad objFormB
Set objFormB = Nothing

-BoFlexson

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top