Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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:
VB
Private Sub cmdSend_Click()
Dim str As String
str = txtValue.Value
DoCmd.Close
DoCmd.OpenForm "frmTwo", acNormal, , , , acWindowNormal, "Value=" + str
End Sub


2nd form

VB
Private Sub Form_Load()
lblPassedValue.Caption = GetTagFromArg(Me.OpenArgs, "Value")
End Sub
 
Share this answer
 
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

C#
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();
}
 
Share this answer
 
v2
Second, using properties approach:

C#
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();
}
 
Share this answer
 
Third, using objects approach
SQL
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;
}
 
Share this answer
 
Fourth, using delegate

C#
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;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900