Using "Or" in a Parameter Query prompt

pianoprodigy

Registered User.
Local time
Today, 04:32
Joined
Apr 22, 2003
Messages
42
In trying to make a certain job more simple, I need to be able to allow a user to click on a shortcut to a query and then enter several parameters. Two of them will be Start Date and End Date. I understand how to do that portion; however, the users must also be able to type in multiple page numbers and display the records where those page numbers appear (one field). For instance, ordinarily, I would just go in and type "46" or "48" or "50" and it would display all of those records where the field contained one of those 3 numbers. I would like the Parameter Query to prompt the user to "Enter Page Numbers" and maybe even give a format; however, when I try this, it doesn't work no matter what syntax I use to enter the page numbers.

Any ideas?
 
piano,

Parameter form has StartDate, EndDate and txtNumbers, Formatted like --> 2,4,6,9,22
That assumes that your PageNumber field in your table is numeric!
Otherwise, txtNumbers should look like this --> '2','4','6','9','22'.

Since users might not like typing all the quotes, a function could do it.
A function could also take input like --> 2,4-7, 13, 16-17

Depending on how many pages there are, you could even use a multi-select ListBox to
get the desired pages.

Code:
Dim qdf As QueryDef
Dim strSQL As String

Set qdf = CurrentDb.QueryDefs("YourQuery")
strSQL = "Select FieldA, FieldB, FieldC " & _
         "From   YourTable " & _
         "Where  StartDate Between #" & Me.StartDate & "# And #" & Me.EndDate & "# And " & _
         "       PageNumber In (" & Me.txtNumbers & ") " & _
         "Order By SomeField;"

qdf.sql = strSQL
qdf.Close

hth,
Wayne
 

Users who are viewing this thread

Back
Top Bottom