how to use a combo box for a query parameter (1 Viewer)

martinr

Registered User.
Local time
Tomorrow, 07:35
Joined
Nov 16, 2011
Messages
74
I need to apply a parameter to a query based on from combo box. I have added the ALL option to the combobox which that the user would select if they want to run the query to show all records;
Eg; Selecting ALL Countries would be the same as having no parameter or a wild card *

ALL Countries
UK
United States
Asia
Europe

I tried an iif statement like:
IIf([forms]![frmSelectReports].[location]="AllCountries",like"*",[forms]![frmSelectReports].[location])
but it didn't work...
 

Mihail

Registered User.
Local time
Tomorrow, 00:35
Joined
Jan 22, 2011
Messages
2,373
Design one more field (column) in your query: ShowRecord: ShowThisRecord([fldCountry])
fldCountry is the field name that show the countries names.
Set Criteria for this field to True

On a PUBLIC module define the function:
Code:
Public Function ShowThisRecord(CountryName As String) As Boolean
Dim SelectedCountry As String
  SelectedCountry = Forms!frmSelectReports.location

  ShowThisRecord = True
  If SelectedCountry = "AllCountries" Then Exit Function
  ShowThisRecord = (SelectedCountry  = CountryName )
End Function

Run the query.
 

martinr

Registered User.
Local time
Tomorrow, 07:35
Joined
Nov 16, 2011
Messages
74
Thanks Mihail,
That worked well!
M.
 

Users who are viewing this thread

Top Bottom