G
Guest
Hi. I have originally posted this question and got the answer but I cannot
seem to find the original post. so sorry, I am posting again. My question
was, I wanted to created a combo box or dropdown list with such values : "10,
15, 20, 25" or simply a text box for user to enter the number and get the top
n records based on that value. I did not want to create one query for each
top whatever and wanted to know if there's a way for to be parameter. and
this is the code I received:
Sub cboTopValues_AfterUpdate()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim n As Integer
Dim strSQL as string
Set db = CurrentDb
n = Val(Me![cboTopValues].Text)
strSQL = "SELECT TOP " & n & " Qty FROM MyTable ORDER BY Qty DESC;"
Set rst = db.OpenRecordset(strSQL)
End Sub
I just cannot get this to work. I replaced "Qty" with balance and "mytable"
with tblTag2 from my table.
I have also created the form with combo box and name it "cboTopValues".
Instead of Sub cboTopValues_AfterUpdate(), I have made it as
Function topvalue()
and created a command button on my form and on click to call that function.
What I want to do is, once the user uses the top whatever value and click on
the bottom, bring up the recrods.
Please help! Thanks
seem to find the original post. so sorry, I am posting again. My question
was, I wanted to created a combo box or dropdown list with such values : "10,
15, 20, 25" or simply a text box for user to enter the number and get the top
n records based on that value. I did not want to create one query for each
top whatever and wanted to know if there's a way for to be parameter. and
this is the code I received:
Sub cboTopValues_AfterUpdate()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim n As Integer
Dim strSQL as string
Set db = CurrentDb
n = Val(Me![cboTopValues].Text)
strSQL = "SELECT TOP " & n & " Qty FROM MyTable ORDER BY Qty DESC;"
Set rst = db.OpenRecordset(strSQL)
End Sub
I just cannot get this to work. I replaced "Qty" with balance and "mytable"
with tblTag2 from my table.
I have also created the form with combo box and name it "cboTopValues".
Instead of Sub cboTopValues_AfterUpdate(), I have made it as
Function topvalue()
and created a command button on my form and on click to call that function.
What I want to do is, once the user uses the top whatever value and click on
the bottom, bring up the recrods.
Please help! Thanks