Click here to Skip to main content
13,086,120 members (84,647 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi Guys,
I have one form with a list box in one form and i want to get the value that was selected in list box to be displayed in text box of another form , like we use session in c# and $_POST[] in php ,How can i use that in Access forms using vb?
give me your valuable suggestions
Posted 5-Mar-12 14:36pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Hi GanesanSenthilvel,

Its nice to hear this from you GanesanSenthilvel but Since I am using Access and back end I am new to vb back end and so i requested for vb code suggestion , Anyhow I am really thankful for your answer

my answer to this is

1st form:
Private Sub cmdSend_Click()
Dim str As String
str = txtValue.Value
DoCmd.Close
DoCmd.OpenForm "frmTwo", acNormal, , , , acWindowNormal, "Value=" + str
End Sub


2nd form

Private Sub Form_Load()
lblPassedValue.Caption = GetTagFromArg(Me.OpenArgs, "Value")
End Sub
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You can pass values between forms in 4 ways. Considering, first form 'Form1' has button1, textBox1. Second form 'Form2' has label named 'label1'. As the first solution, let us use constructor

public Form2(string strTextBox)
{
  InitializeComponent();
  label1.Text=strTextBox;
}
 
private void button1_Click(object sender, System.EventArgs e)
{
    Form2 frm=new Form2(textBox1.Text);
    frm.Show();
}
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Second, using properties approach:

public string _textBox1
{
    get{return textBox1.Text;}
}
public string _textBox
{
   set{label1.Text=value;}
}
private void button1_Click(object sender, System.EventArgs e)
{
     Form2 frm=new Form2();
     frm._textBox=_textBox1;
     frm.Show();
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Third, using objects approach
public class Form1 : System.Windows.Forms.Form
{
 public System.Windows.Forms.TextBox textBox1;
 
private void button1_Click(object sender, System.EventArgs e)
{
    Form2 frm= new Form2();
    frm.frm1=this;
    frm.Show();
}
 
public class Form2 : System.Windows.Forms.Form
{
     private System.Windows.Forms.Label label1;
     public Form1 frm1;
 
private void Form2_Load(object sender, System.EventArgs e)
{
    label1.Text=((Form1)frm1).textBox1.Text;
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Fourth, using delegate

public delegate void delPassData(TextBox text);
 
private void button1_Click(object sender, System.EventArgs e)
{
    Form2 frm= new Form2();
    delPassData del=new delPassData(frm.funData);
    del(this.textBox1);
    frm.Show();
}
 
public void funData(TextBox txtForm1)
{
    label1.Text = txtForm1.Text;
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 6 Mar 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100