So I have a form, report and a table
What I want to do is to pool data from the table into the report using criteria in the form.
Let’s say the table has columns: “company”, “fund”, “return”, “deviation”, “variance”
On the form (I have it working) I can choose the name of the company from a first combo box and then I can choose a fund from the second combo box.
What I want to do further is to select from the third combo box one of the three variables (column headers from the table - return, deviation and variance)
I have setup the third combo box to show me the three options (return, deviation and variance), now I want to press “OK” button and have a report open that would have a textbox with the company name, another textbox with the fund name and the last textbox with the value of the variable I choose in the third combo box in my form.
I managed to make everything working except the third textbox displaying the value of the variable chosen in the third combobox.
The VBA Code I used is:
Code:
Dim table_name As String
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb()
Dim sql As String
sql = "Select * from [my_table] where company=" & Forms![my_form]![first_combo_box]
Set rst = DB.OpenRecordset(sql)
Third_text_box.Value = rst![forms!my_form!third_combo_box.value]
rst.Update
rst.Close
it won’t work, however if I change the line:
Code:
Third_text_box.Value = rst![forms!my_form!third_combo_box.value]
To
Code:
Third_text_box.Value = rst![variance]
It will work and display in the third textbox the value of the variance for the corresponding company and fund.
Any help would be welcome