|
-
Aug 26th, 2009, 09:29 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Pass Variable from form to form
Is it possible to pass a variable set in one form to another?
-
Aug 26th, 2009, 09:32 AM
#2
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.
-
Aug 26th, 2009, 09:50 AM
#3
Thread Starter
Addicted Member
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'.
-
Aug 26th, 2009, 09:58 AM
#4
Hyperactive Member
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. 
-
Aug 26th, 2009, 10:12 AM
#5
Thread Starter
Addicted Member
Re: Pass Variable from form to form
Does my last post make sense?
-
Aug 26th, 2009, 10:14 AM
#6
Frenzied Member
Re: Pass Variable from form to form
What is frm1.id supposed to be referencing?
-
Aug 26th, 2009, 10:16 AM
#7
Thread Starter
Addicted Member
Re: Pass Variable from form to form
It references the first originating form and its variable.
-
Aug 26th, 2009, 10:18 AM
#8
Re: Pass Variable from form to form
 Originally Posted by raptormanad
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 -
-
Aug 26th, 2009, 10:19 AM
#9
Frenzied Member
Re: Pass Variable from form to form
What is the variable id, a string, a numeric value, a control name?????
-
Aug 26th, 2009, 10:21 AM
#10
Thread Starter
Addicted Member
Re: Pass Variable from form to form
id is a variable from the previous form which is a field resulting from a sql statement.
-
Aug 26th, 2009, 10:23 AM
#11
Frenzied Member
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
-
Aug 26th, 2009, 10:24 AM
#12
Re: Pass Variable from form to form
 Originally Posted by raptormanad
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 -
-
Aug 26th, 2009, 10:25 AM
#13
Thread Starter
Addicted Member
Re: Pass Variable from form to form
 Originally Posted by stanav
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|