Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting all records through a query via a function 1

Status
Not open for further replies.

mearesp

Technical User
Feb 4, 2003
3
GB
Sorry, this is probably a bit basic but it has got me stumped. I am learning Access 97.
I wanted to have two buttons on a form that ran the same
query but with different parameters. e.g. one selected records called "A10" and then the other selected all records (*). I have used the global function() route as explained in various articles and called the function() from the Criteria field on the query design view. When I put "A10" into the code in the function under the button everything works fine. When I put * or "*" or " LIKE "*"" to get all records it doesn't find any match. Where have I gone wrong?
 
Please provide your SQL and your function.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
The basic idea is to have a simple form with two buttons. Button One forces the query to select the fields with A in Column 1, and the second forces the query to select all records. The "A" wotrks well but the * does not work, nor does "*" or " *" or LIKE * ...
I suspect it is what is returned from GetParam() into the Query but I can't see the resulting SQL code that runs, so don't know what is missing.
Here is the code
' Simple query
' Database has two columns
' First has A, B, C in
' Scond has 1, 2, 3 in
' Query1 was created in Desugn view, I have not written the SQL code
'
'Query1
SELECT Table1.First, Table1.Second
FROM Table1
WHERE (((Table1.First)=getParam(1)));

'-------------------
' Code module for the Form Buttons. These are link by name to the form button On_Click action.
' Two Buttons, one called A, and the other All
'
Option Compare Database

Private Sub Button_A_Click()
Dim stDocName As String
Call SetParam("A", 1)
stDocName = "Query1"
DoCmd.OpenQuery stDocName, acNormal, acEdit
End Sub

Private Sub Button_All_Click()
Dim stDocName As String
Call SetParam("*", 1)
stDocName = "Query1"
DoCmd.OpenQuery stDocName, acNormal, acEdit
End Sub

'-------------------
' Module 1 to give global function call.
'
Option Compare Database

Dim arrParameter(1) As Variant

Public Sub SetParam(ByVal InputVal, ByVal paramID)
arrParameter(paramID) = InputVal
End Sub

Public Function GetParam(ByVal paramID)
GetParam = arrParameter(paramID)
End Function
 
You would need to use a sql of:
SELECT Table1.First, Table1.Second
FROM Table1
WHERE (((Table1.First) Like getParam(1)));


Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top