Link to home
Start Free TrialLog in
Avatar of kate_y
kate_y

asked on

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"
Avatar of [ fanpages ]
[ fanpages ]

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.
Avatar of kate_y

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of [ fanpages ]
[ fanpages ]

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not sure but there is aproperty for combo boox called " Modifier"
change  Modifier attribute to internal or public
and then try sa fanpages suggested
Avatar of kate_y

ASKER

i found a solution. thanks.

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

Thanks for closing the question.