send a value from a form to another form or just access that value somehow

Posted on 2006-05-02
Last Modified: 2010-04-23
I am trying to get a value from a form to use in a different form. The one form has a textbox that the user enters their employee ID into. Then that form uses that ID to decide what form to go to next. So it then chooses the clock in and out form which needs the employee ID that the user entered on the other form. I've been trying to set variables to public and also I tried making get and set functions and using them to retrieve the value.
here is some code...

Public rEmpID As String        (this is at the top of the login form)

setEmp(dr(0))            (this is in a button click procedure retrieving the employeeID from an executereader
                                    but I maybe could also get the value from the textbox)

Public Function setEmp(ByVal emp As Integer)
        rEmpID = emp                                               (my set and get functions located in the login form)
    End Function
Public Function returnEmp()
        Return rEmpID
End Function

Public loginForm As New LogForm                    (this is at the top of the clock in and out form)

employeeID = loginForm.returnEmp()           (this is in a button click procedure in the clock in and out form)

So I'm not sure how to make this work, any ideas would be great!
Question by:JoshWegener
    LVL 34

    Expert Comment

    by:Brian Crowe
    It is poor design practice to make controls or variables public.  It is a much better practice to create property methods for the variables you wish to expose.
    public readonly property EmployeeID() as integer
          if isnumeric(txtEmployeeID.text) then
             return cint(txtemployeeid.text)
             return -1
          end if
       end get
    end property
    LVL 34

    Expert Comment

    by:Brian Crowe
    as for the usage...

    dim iEmployeeID as integer

    iEmployeeID = loginForm.EmployeeID
    LVL 1

    Author Comment

    Ok I put that code in and it still doesn't work, would it be because when I go to the clock in and out form I first hide the login form so would it then be clearing out the textbox? I need to know how to make it not clear the textbox or to just save the value in the textbox to get later before it clears it out whenever its doing it.
    LVL 34

    Accepted Solution

    please post the code where you are instantiating the form with the employeeid textbox.
    LVL 1

    Author Comment

    Ah yes I didn't have a textbox declared to put the value from the form textbox into.
    I do now :-) Thanks so much!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now