Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / April 2006

Tip: Looking for answers? Try searching our database.

Top N value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GEORGIA - 27 Apr 2006 02:45 GMT
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
Tom Wickerath - 27 Apr 2006 08:06 GMT
Hi Georgia,

I think this is the thread you are looking for:

http://groups.google.com/group/microsoft.public.access/browse_frm/thread/d262f57
f822ba67a/e582771b10037769


Tom Wickerath, Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

> 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
[quoted text clipped - 30 lines]
> the bottom, bring up the recrods.  
> Please help! Thanks
GEORGIA - 27 Apr 2006 13:53 GMT
thank you very much!  

got it to work now...

> Hi Georgia,
>
[quoted text clipped - 42 lines]
> > the bottom, bring up the recrods.  
> > Please help! Thanks
GEORGIA - 27 Apr 2006 14:07 GMT
one quick questions...

as it mentioned it in the link below.. it is excuting after_update. like so:
Private Sub cboTopValues_AfterUpdate()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim n As Integer
Dim strsql As String

Set db = CurrentDb


n = Val(Me![cboTopValues].Text)

strsql = "SELECT TOP " & n & "  [balance], tbltag2.* from tbltag2 order by
[balance] desc;"

db.QueryDefs.Delete "qrytopx"
Set qdf = db.CreateQueryDef("qrytopx", strsql)

DoCmd.OpenQuery "qrytopx", acNormal, acEdit

Exit_cmdRunQuery_Click:
   Exit Sub

Err_cmdRunQuery_Click:
   If Err.Number = 3265 Then
       Resume Next
   Else
       MsgBox Err.Description
       Resume Exit_cmdRunQuery_Click
   End If
End Sub

and it works perfectly.  

however, when i try to put it under

Private Sub Command2_Click()

End Sub

it gives me run-time error 2185.  you can't reference a property or method
for a control unless the conntrol has the focus.  
i'm not exactly sure what that means.  I tried setting the box on focus but
that didn't work.
thanks!

> Hi Georgia,
>
[quoted text clipped - 42 lines]
> > the bottom, bring up the recrods.  
> > Please help! Thanks
GEORGIA - 27 Apr 2006 14:26 GMT
ok sorry.. i spoke too soon. I guess I should have thought about it before
replying..

i replaced
n = Val(Me![cboTopValues].Text)
to
n = Val(Me![cboTopValues].value)
then it works under click event.

thanks!

> one quick questions...
>
[quoted text clipped - 90 lines]
> > > the bottom, bring up the recrods.  
> > > Please help! Thanks
Tom Wickerath - 27 Apr 2006 15:58 GMT
Hi Georgia,

Glad to see that you got it worked out.

Good luck on your project.


Tom Wickerath, Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

> ok sorry.. i spoke too soon. I guess I should have thought about it before
> replying..
[quoted text clipped - 6 lines]
>
> thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.