-
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).]
-
in your second form:
dim strVariable as string
strVariable = form1!GetName
-
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?
-
Martin, you're right, that's what happens when I'm doing 4 things at once. Thanks for catching that.
-
Neither worked. I get this error "Control GetName not found!" Any suggestions?
-
strVariable = form1!GetName
change to:
strVariable = form1.GetName
-
Great! Thanks. Appreciate the help!
-
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.
Code:
' 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?