Results 1 to 8 of 8

Thread: Passing variables from one form to another

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    34

    Post

    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).]

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    in your second form:

    dim strVariable as string
    strVariable = form1!GetName


  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    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?

  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    Martin, you're right, that's what happens when I'm doing 4 things at once. Thanks for catching that.

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    34

    Post

    Neither worked. I get this error "Control GetName not found!" Any suggestions?

  6. #6
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    strVariable = form1!GetName

    change to:

    strVariable = form1.GetName

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2000
    Posts
    34

    Post

    Great! Thanks. Appreciate the help!

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width