A way to change query from a value on a form

  • Thread starter Thread starter John
  • Start date Start date
J

John

Is there a way to programmatically change the "Top Values"
properties in a query by what a user selects on form?

Thanks,
John
 
Check out the help on the TopValues property... It can ONLY be coded in the
SQL statement. Thus, simply open your query design in SQL view and copy and
paste this into a module. Then try the following (where the SQL statement is
the copied query from your query definition and the qryQueryName is the name
of the query)... You may have to pass a true/false value as well, to
indicate if you are selecting the top x percentage, or x number of records..


Sub ChangeTopValue(inValue As Integer)

Dim myQuery As DAO.QueryDef

Set myQuery = CurrentDB().QueryDefs("qryQueryName")

myQuery.SQL = "SELECT TOP " & inValue & " [Table1].[Field] FROM
[Table1];"

myQuery.Close

Set myQuery = Nothing

End Sub
 
Back
Top