Allen,
How would that work with my SQL?, would this code go in the afterupdate
property of my 'input number' control? which you currently have ref as
'txtTop'. My query is called: 'Test Points generator'. its underlying
Table
is called 'Test_Points_Feeder'
Dim strSql As String
If Me.txtTop >= 1 Then
strSql = "SELECT TOP " & Me.txtTop
Else
strSql = "SELECT "
End If
strSql = strSql & " Test_Points_Feeder.* FROM Test_Points_Feeder;"
CurrentDb.QueryDefs("Test Points generator").SQL = strSql
My Current SQL (Test Points generator):
SELECT TOP 5 Test_Points_Feeder.Run_No, Test_Points_Feeder.Point_Quiz_ID,
Test_Points_Feeder.Run_point_Venue_A,
Test_Points_Feeder.Run_point_Address_A,
Date() AS TestDate
FROM Test_Points_Feeder
GROUP BY Test_Points_Feeder.Run_No, Test_Points_Feeder.Point_Quiz_ID,
Test_Points_Feeder.Run_point_Venue_A,
Test_Points_Feeder.Run_point_Address_A,
Date(), Rnd([Point_Quiz_ID])
HAVING (((Test_Points_Feeder.Run_No) Between
[Forms]![frm_Runs].[RunFromCombo] And [Forms]![frm_Runs].[RunToCombo]))
ORDER BY Rnd([Point_Quiz_ID]);
Allen Browne said:
It's not that difficult, and it doesn't really matter how complex the SQL
statement is. You just break it into 2 after TOP, and piece it back
together
with the number in between.
This kind of thing:
Dim strSql As String
If Me.txtTop >= 1 Then
strSql = "SELECT TOP " & Me.txtTop
Else
strSql = "SELECT "
End If
strSql = strSql & " Table1.* FROM Table1;"
CurrentDb.QueryDefs("Query1").SQL = strSql
Allen,
thanks for replying with a definitive answer; building the statement
dynamically sounds complex and beyond my abiliites. The other point is
that
this query is part of a group of in-development interlinked queries,
which
means I like to see the QBE grid as i go along.
regards
:
No. You cannot use a parameter for the TOP n value.
You could build the query statement dynamically, and assign it to the
SQL
property of the QueryDef.
Is it possible to have a form control that can adjust the 'Top n'
value
that
is based on a criteria in a query?
I have a query that I want to use with of a varying number of Top n
values
based on the dynamic figure that I input into a control on a form.
Is
this
possible?.
I seem to remember from the early days of Access 1.0 & 2.0 that the
'Top
n'
value can be used in a criteria on the QBE grid, or did I imagine
that?