• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

how to pass value between two forms using VBA in Access 2003?

Hi, this is what i am trying to do.

I have a combo box in form1 and a button. User select a value from the combo box and click then click the button. it opens another form which does quey using the value that user selected from the combo box.

this is the query code in the form2. i want x = form1's combo box value. please help.

Dim x As String

x = form1's combo box value

    Set db = CurrentDb
   
    strSQL = "SELECT id, name FROM T_test where name = x"
   
    Set rst = db.OpenRecordset(strSQL)
   
    Set Me.Recordset = rst
   
    Me.txtName.ControlSource = "Name"
       Me.id.ControlSource = "id"
0
kate_y
Asked:
kate_y
  • 3
  • 2
  • 2
1 Solution
 
[ fanpages ]IT Services ConsultantCommented:
strSQL = "SELECT id, name FROM T_test where name = " & Chr$(34) & Form1.ComboBox1.Value & Chr$(34)

Where Form1 is the name of "form1", and "ComboBox1" is the name of the Combo-Box control on "form1".

BFN,

fp.
0
 
kate_yAuthor Commented:
but when i directly use the first form name in the second form, it didn't give me the option use the .comboBox.value

thanks
0
 
[ fanpages ]IT Services ConsultantCommented:
You mean the Intellisense did not recognise Form1. and the pop-up a list of controls?

In that case, try this:


strSQL = "SELECT id, name FROM T_test where name = " & Chr$(34) & Forms("Form1").Controls("ComboBox1").Value & Chr$(34)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hiteshgupta1Commented:
Not sure but there is aproperty for combo boox called " Modifier"
change  Modifier attribute to internal or public
0
 
hiteshgupta1Commented:
and then try sa fanpages suggested
0
 
kate_yAuthor Commented:
i found a solution. thanks.

 x = cboTest.Value
   
  Form_frm_subtest.RecordSource = "SELECT * FROM T_test WHERE Name = '" & x & "'"

0
 
[ fanpages ]IT Services ConsultantCommented:
Thanks for closing the question.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now