Simple Software Solutions
Hi
Think I know what you mean?
You have a table that contains lets say 1000 records, the user want to run a query based on this table, but does not want to run it with all 1000 records, and to this effect they are prompted to supply the number of records they want to sample.
Dim iWant As Integer
Dim strSQL As String
iWant = InputBox(.....)
strSQL = "SELECT TOP " & CStr(iWant) & " FROM MyTable;"
If so, then there is an easy solution, use the QueryDefs object to change the SQL statement of the underlying query so that it changes
Sample Code:
Dim dbsCurrent As Database
Dim qryTest As QueryDef
Set dbsCurrent = CurrentDb
Set qryTest = dbsCurrent.QueryDefs("Employee List")
qryTest.SQL = strSQL
To summarise.
The user provides a value
This is parsed in a string to create a valid SQL statement
This string is then used to recreate the SQL statement for the query
The user runs the query.
You can also use PERCENTS as well as numbers, so the user could enter a value as a percentage amount, the strSQL would read:-
strSQL = "SELECT TOP 10 PERCENT FROM MyTable;"
Code Master
