benkingery
10-23-2009, 06:27 AM
I have a query that I'd like to limit the results to. I've been able to find out that the syntax is SELECT TOP 20 or SELECT TOP 100, but my question is what do I do when I would like my top number to be a dynamic number that I put into a text box on a form?
Anyone help on that one?
DCrake
10-23-2009, 06:36 AM
To do that you would need to go down the vba route with query defs and re creating the query sql prior to running the query.
David
benkingery
10-23-2009, 06:51 AM
I figured that would be the case. Any idea on syntax specifically for the part I want to be dynamic?
Place the VBA on the form, right? Not called from a module?
namliam
10-23-2009, 07:00 AM
dont matter,
Make a query call it "yourotherquery_Default" and dont use any top statement in it...
Now in code add your top... Assuming when executed from within the form
Currentdb.querydefs("Yourotherquery").sql = "Select top " & Me.[TheControlContainingTheLimit] & mid(Currentdb.querydefs("Yourotherquery_Default").sql,7)
benkingery
10-23-2009, 08:21 AM
Hmmmm. how about if the SQL statement is an UPDATE statement instead of just a SELECT?
BTW, what's the difference between using Docmd.runsql and Currentdb.....?
namliam
10-26-2009, 01:42 AM
DoCmd by default will show the "You are affecting ... records" message when executing a Update/Delete/Create table statement. Currentdb will not...