Filtering a query using a variable (1 Viewer)

Shas91

Member
Local time
Today, 05:15
Joined
Nov 26, 2019
Messages
41
Hi !

I'm bit frustrated, I just can't select all in a query. It is allways hard to explain so I have made a small access program to show what I mean.

If You start frmProject_Filter and chose Adam Adamsson in the dropdown meny and press "Start Filtering" It start up start up and show a filtered qryProject for two seconds, just as it should. And it works like charm with all manager in the dropdown meny so far so god !

The problem is when it comes to show all... It shows nothing... I have tried "like *" , "*" and much more. If You use the asterix directly in the query it works but not as a variable...

It's problebly a very litle fault but it still a fault... Is there anyone who can assist and save my weekend...

// Shas
 

Attachments

  • Test.accdb
    440 KB · Views: 50

Ranman256

Well-known member
Local time
Today, 08:15
Joined
Apr 9, 2015
Messages
4,337
instead of param query, make a continuous form that shows all data,
put UNBOUND controls on the header area for it to filter the data,
user then clicks FIND btn which checks the controls on what to filter:

Code:
Public Sub btnFIND_Click()
Dim sSql As String, sWhere As String

sWhere = "1=1"

    'the query is built depending on the various filters the user picks...
If Not IsNull(cboState) Then sWhere = sWhere & " and [state]='" & cboState & "'"
If Not IsNull(txtName) Then sWhere = sWhere & " and [Name]='" & txtName & "'"
If Not IsNull(chkContact) Then sWhere = sWhere & " and [Contact]=" & chkContact.Value

 'use it to filer the form records
if sWhere = "1=1" then
  me.filterOn = false
else
  me.filter = sWhere
  me.filterOn = true
endif
END SUB
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:15
Joined
Sep 21, 2011
Messages
14,305
That does not even work? :(

1697722000043.png
 

Ranman256

Well-known member
Local time
Today, 08:15
Joined
Apr 9, 2015
Messages
4,337
did you use BUILDER to get the correct control path?
misspellings can happen if you type it manually or the field doesn't exist.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:15
Joined
Sep 21, 2011
Messages
14,305
Here is one way?
 

Attachments

  • Gasman Test (2).accdb
    588 KB · Views: 57

Shas91

Member
Local time
Today, 05:15
Joined
Nov 26, 2019
Messages
41
Hi !

First sorry for my late respons... As You alredy has notice, "Formulär" is a swedish translation for "forms". Its rather stupid of access to make country versions....

I saw Your code... I have never seen that... So easy and it workes perfect.

Thank You

// Stefan
 

Shas91

Member
Local time
Today, 05:15
Joined
Nov 26, 2019
Messages
41
instead of param query, make a continuous form that shows all data,
put UNBOUND controls on the header area for it to filter the data,
user then clicks FIND btn which checks the controls on what to filter:

Code:
Public Sub btnFIND_Click()
Dim sSql As String, sWhere As String

sWhere = "1=1"

    'the query is built depending on the various filters the user picks...
If Not IsNull(cboState) Then sWhere = sWhere & " and [state]='" & cboState & "'"
If Not IsNull(txtName) Then sWhere = sWhere & " and [Name]='" & txtName & "'"
If Not IsNull(chkContact) Then sWhere = sWhere & " and [Contact]=" & chkContact.Value

'use it to filer the form records
if sWhere = "1=1" then
  me.filterOn = false
else
  me.filter = sWhere
  me.filterOn = true
endif
END SUB
Hi thanks for Your effort... Gasman solved this a bit easier this time
 

sonic8

AWF VIP
Local time
Today, 14:15
Joined
Oct 27, 2015
Messages
998
As You alredy has notice, "Formulär" is a swedish translation for "forms". Its rather stupid of access to make country versions....
It's not the core topic of this thread, nonetheless:
I've got only experience with this with the German localization of Access. There the problem can be (mostly) avoided by typing the English expressions. E.g. you type in "Forms", Access will automatically translate this to the German "Formulare" but it then will also be able to re-translate it back to English. However, if you directly type in "Formulare", Access is sometimes not able to translate this back to "Forms".
 

Shas91

Member
Local time
Today, 05:15
Joined
Nov 26, 2019
Messages
41
It's not the core topic of this thread, nonetheless:
I've got only experience with this with the German localization of Access. There the problem can be (mostly) avoided by typing the English expressions. E.g. you type in "Forms", Access will automatically translate this to the German "Formulare" but it then will also be able to re-translate it back to English. However, if you directly type in "Formulare", Access is sometimes not able to translate this back to "Forms".
 

Shas91

Member
Local time
Today, 05:15
Joined
Nov 26, 2019
Messages
41
Hi I'm always trying to use the english expression with thoose problem You describe as a fact. Well it is as it is...
 

Users who are viewing this thread

Top Bottom