Article ID: 100131
Article Last Modified on 1/18/2007
182568 ACC97: Microsoft Access 97 Sample Queries Available in Download Center
Query: ParamQuery
--------------------
Type: Select Query
Field: EmployeeID
Table: Employees
Show: True
Field: LastName
Table: Employees
Show: True
NOTE: In Microsoft Access 2.0, there is a space in the Employee ID
and Last Name field names.
Field: InStr([Last Names separated by commas,Blank=All],[LastName])
Criteria: > 0 Or Is Null
Show: FalseFuller,King,Callahan
'************************************************************
'Declarations section of the module.
'************************************************************
Option Explicit
'============================================================
' The GetToken() function defines the delimiter character.
'============================================================
Function GetToken (stLn, stDelim)
Dim iDelim as Integer, stToken as String
iDelim = InStr(1, stLn, stDelim)
If (iDelim <> 0) Then
stToken = LTrim$(RTrim$(Mid$(stLn, 1, iDelim - 1)))
stLn = Mid$(stLn, iDelim + 1)
Else
stToken = LTrim$(RTrim$(Mid$(stLn, 1)))
stLn = ""
End If
GetToken = stToken
End Function
'============================================================
' The InParam() function is the heart of this article. When
' the query runs, this function causes a query parameter
' dialog box to appear so you can enter a list of values.
' The values you enter are interpreted as if you
' had entered them within the parentheses of the In() operator.
'============================================================
Function InParam (Fld, Param)
Dim stToken as String
'The following two lines are optional, making queries
'case-insensitive
Fld = UCase(Fld)
Param = UCase(Param)
If IsNull(Fld) Then Fld = ""
Do While (Len(Param) > 0)
stToken = GetToken(Param, ",")
If stToken = LTrim$(RTrim$(Fld)) Then
InParam = -1
Exit Function
Else
InParam = 0
End If
Loop
End Function
FieldName: InParam([CustomerID],[ Enter ID list using commas and no _
spaces:])
Show: False
Criteria: True
NOTE: In versions 1.x and 2.0, there is a space in the Customer ID
field name.
Enter ID list using commas and no spaces:
CHOPS,EASTC,FAMIA
BLUEL,CACTP,DOLLC
IN("A*", "BON*", "CRATE???")
Additional query words: queries
Keywords: kbhowto kbprogramming kbusage KB100131