+ Reply to Thread
Results 1 to 4 of 4

Passing data between forms

Hybrid View

  1. #1
    Registered User
    Join Date
    02-10-2011
    Location
    Seattle, Wa
    MS-Off Ver
    Excel 2003
    Posts
    4

    Passing data between forms

    Hi all -

    I'm attempting to re-write a customer database I built, using classes and I'm having troubles.

    assigning the varibale to the result of a function - here is the class def
    Class Module name is CEmployee
    Private Pname As String
    Public Property Get name() As String
        name = Pname
    End Property
    Public Property Let name(Value As String)
        Pname = Value
    End Property
    here is the Module with def, and function
    Public PersonsName As String
    Public emp As CEmployee
    Public Function add_Name(name) As String
    Set emp = New CEmployee
        emp.name = name
    End Function
    now the problem comes in with my two forms...
    form 1 code =
    Private Sub CommandButton1_Click()
        PersonsName = add_Name(TextBox1.Value)
        PersonsName = emp.name
        MsgBox PersonsName
    End Sub
    form 2 code =
     
    Private Sub CommandButton1_Click()
        MsgBox PersonsName
    End Sub
    is this the only way to get the result of function. I thought personsname = add_name(textbox1.value) would be enoungh to assign the variable personsname to the result of the add_name() function

    is there a better way to do this?
    Last edited by JamesPLile; 02-15-2011 at 12:32 AM. Reason: forgot to add the [code] tags

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Passing data between forms

    Your function is not returning a value.
    Your code is confusing so I'm not sure what it should return.

    Public Function add_Name(name) As String
    Set emp = New CEmployee
        emp.name = name
    
       add_Name = name ' or whatever you want returned
    End Function
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    02-10-2011
    Location
    Seattle, Wa
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Passing data between forms

    I'm sorry that it is confusing, its mostly copied from a forum some where.

    the add_Name = name worked though.

    and I understand why thank you

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Passing data between forms

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1