Selecting records matching user input

G

Guest

My application asks the user to specify a combination of criteria for selecting records they want out of a table. They input things like: beginning and ending dates (a date range) and the values of two particular fields. They also specify which of three ways to sort the records. Records matching these criteria will then appear on a report in the sort order requested

I can't use a query for this since user input will be different each time. How do I take the user input and use it to select out and sort the records they want? Can it be done directly from the table with a recordset statement like this?

Set rs = db.OpenRecordset( ...

ctda
 
T

TPratt

Below is an example of a form that would ask the user to enter a last
name into a text box (txtLastName) and click a command button named "CmdGo".
The form would then return a list of all people in the table with that last
name.


Const strSQLselect = "Select [LastName], [FirstName] From [TblNames] "
Const strSQLwhere = "Where (([LastName]) = "

Dim strSQL as String

Private Sub CmdGo_Click()

strSQL = strSQLselect & strSQLwhere & """" & txtLastName.Value & """"
& ")"

me.recordsource = strSQL

End Sub

A simplified example but should be enough to get you going...

Tom


ctdak said:
My application asks the user to specify a combination of criteria for
selecting records they want out of a table. They input things like:
beginning and ending dates (a date range) and the values of two particular
fields. They also specify which of three ways to sort the records. Records
matching these criteria will then appear on a report in the sort order
requested.
I can't use a query for this since user input will be different each
time. How do I take the user input and use it to select out and sort the
records they want? Can it be done directly from the table with a recordset
statement like this?:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top