Results 1 to 13 of 13

Thread: [RESOLVED] Pass Variable from form to form

  1. #1

    Thread Starter
    Addicted Member raptormanad's Avatar
    Join Date
    Oct 2008
    Posts
    224

    Resolved [RESOLVED] Pass Variable from form to form

    Is it possible to pass a variable set in one form to another?

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Pass Variable from form to form

    Yes, passing data between forms is asked several times a week, and doing a forum search here will turn up tons of results and answers to this.

  3. #3

    Thread Starter
    Addicted Member raptormanad's Avatar
    Join Date
    Oct 2008
    Posts
    224

    Re: Pass Variable from form to form

    I did some looking around and tried something like:

    Code:
    Public Class frm2
    
        Private Sub frm2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Label6.Text = frm1.id
        End Sub
    
    End Class
    But it says:

    Error 105 'id' is not a member of 'Project1.frm1'.

  4. #4
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    Re: Pass Variable from form to form

    Yes. I did from a search form.

    Code:
    Private Sub DataGridView1_CellClick1(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    
            DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.CurrentCell.RowIndex)
    
            frmBookingForm.txtAccountNo.Text = DataGridView1.CurrentCell.Value
    
            Me.Close()
        End Sub
    In this case I passed the variable to the form I wanted the variable in and then closed the search form.
    It was much easier in VB6, but I am now liking Vb.Net alot more.

  5. #5

    Thread Starter
    Addicted Member raptormanad's Avatar
    Join Date
    Oct 2008
    Posts
    224

    Re: Pass Variable from form to form

    Does my last post make sense?

  6. #6
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: Pass Variable from form to form

    What is frm1.id supposed to be referencing?
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  7. #7

    Thread Starter
    Addicted Member raptormanad's Avatar
    Join Date
    Oct 2008
    Posts
    224

    Re: Pass Variable from form to form

    It references the first originating form and its variable.

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Pass Variable from form to form

    Quote Originally Posted by raptormanad View Post
    Does my last post make sense?
    Yes, it made sense. But in order for the code to work, you need to add the "id" member to your frm1 class. It can be a public property or variable.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  9. #9
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: Pass Variable from form to form

    What is the variable id, a string, a numeric value, a control name?????
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  10. #10

    Thread Starter
    Addicted Member raptormanad's Avatar
    Join Date
    Oct 2008
    Posts
    224

    Re: Pass Variable from form to form

    id is a variable from the previous form which is a field resulting from a sql statement.

  11. #11
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: Pass Variable from form to form

    And what is id displayed in on your frm1?

    you could do

    Label6.Text = frm1.TextBoxID.Text

    or

    Label6.Text = frm1.LabelID.Text

    or

    Label6.Text = frm1.cboID.SelectedText
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  12. #12
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Pass Variable from form to form

    Quote Originally Posted by raptormanad View Post
    id is a variable from the previous form which is a field resulting from a sql statement.
    And where is it declared? Is it declared as class level variable with appropriate access modifier in frm1?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  13. #13

    Thread Starter
    Addicted Member raptormanad's Avatar
    Join Date
    Oct 2008
    Posts
    224

    Re: Pass Variable from form to form

    Quote Originally Posted by stanav View Post
    Yes, it made sense. But in order for the code to work, you need to add the "id" member to your frm1 class. It can be a public property or variable.
    Bingo, that got it. Thanks for all the replies!

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