PDA

Click to See Complete Forum and Search --> : Passing variables from one form to another


mecca
Jan 26th, 2000, 12:11 AM
Suppose I Dim GetName As String and want to pass that variable to another form. The variable is being retrieved from a database. Now I need to pass it to another form and use it in various ways within that form. Any suggestions?

[This message has been edited by mecca (edited 01-26-2000).]

netSurfer
Jan 26th, 2000, 12:12 AM
in your second form:

dim strVariable as string
strVariable = form1!GetName

MartinLiss
Jan 26th, 2000, 12:36 AM
In order for netSurfer's suggestion to work, GetName needs to be defined as Public in Form1's Declarations area. You will also need to change the exlamation point to a period in the code.

'In Form1
Public GetName As String

'In Form2
Dim strVariable As String
strVariable = form1!GetName


------------------
Marty
Why is it called lipstick if you can still move your lips?

netSurfer
Jan 26th, 2000, 12:37 AM
Martin, you're right, that's what happens when I'm doing 4 things at once. Thanks for catching that.

mecca
Jan 26th, 2000, 12:45 AM
Neither worked. I get this error "Control GetName not found!" Any suggestions?

netSurfer
Jan 26th, 2000, 12:50 AM
strVariable = form1!GetName

change to:

strVariable = form1.GetName

mecca
Jan 26th, 2000, 12:57 AM
Great! Thanks. Appreciate the help!

MartinLiss
Jan 26th, 2000, 01:01 AM
You can also do what you want by creating a new Property for Form1. In the example below I changed your GetName to MyName. I would have used "Name", but of course every form already has a "Name" property.

' In Form1
Option Explicit

Private m_Name As String

Private Sub Form_Load()

MyName = "Marty"
Form2.Show

End Sub
Public Property Get MyName() As String

MyName = m_Name
End Property
Public Property Let MyName(ByVal sName As String)

m_Name = sName

End Property
'=====================================
' In Form2
Private Sub Command1_Click()

MsgBox Form1.MyName

End Sub


------------------
Marty
Why is it called lipstick if you can still move your lips?