Using Parameter as Criterion in design View

W

WSF

Access 97
Thanks to Nikos Yannacopoulos over a year ago I have been using the
following very successfully to filter record returns in a query.
I create a public variable text value called BranchID, taken from a lookup
text field in a table, and use the following function as the query
criterion. For example

Public Function Get_BranchID()
Get_BranchID = BranchID
End Function

In the query criteria line I enter =Get_BranchID()
This works fine. But now I would like to also be able to pull all records
from the query.
Obviously, in design view, I would do this by manually deleting the
criterion [=Get_BranchID()] and leaving it blank.
Entering an Asterisk "*" creates the criterion Like "*". Either way I get
all records.
But is there a way to still use the Function / Criterion I have been using
to pull all records?
What "value" would I need to enter in the field of the lookup table?
I'm stumped.

Any help gratefully appreciated

WSF
 
R

Rebecca Riordan

Can you just change your function:

Public Function Get_BranchID()
If BranchID = "" Then
BranchID = "*"
Else
GetBranchID = BranchID
EndIf
End Function

and then use like in your criteria?

HTH

--
Rebecca Riordan, MVP

Seeing Data: Designing User Interfaces
Designing Relational Database Systems, 2nd Edition
www.awprofessional.com

Microsoft SQL Server 2000 Programming Step by Step
Microsoft ADO.NET Step by Step
www.microsoft.com/mspress
 

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