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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filterOn in Access 2013

Status
Not open for further replies.

fedum

Technical User
Mar 22, 2004
104
BE
I tried to use a filter in a query that I use to open an Excelsheet with this data.
First I declare a strFilter as string, I give this a value with a inputwindow, then I open the query en build the criteria. Then use Me.Filter = strFilter, put the Me.FilterOn = true. The strange thing is that the filterOn stays FALSE. What can be the reason???
Thanks for replay.
 
Add messages to test the Filter value and see if FilterOn=True runs.

combo
 
Dear combo,
If I debug and put a breakpoint into the code I see that it stays FALSE. Is this not a good way to check?
Thanks.
 
The code is:
Private Sub btnOk_Click()
Dim filterStartPostcode As String
Dim filterEindePostcode As String
Dim filterNaam As String
Dim filterWaarde As String
Dim strFilter As String

On Error GoTo Err_afhandeling
Select Case fraFilterkeuze.Value
Case 1
filterStartPostcode = InputBox("Geef de beginwaarde van de postcode", "Postcode")
filterEindePostcode = InputBox("Geef de eindwaarde van de postcode", "Postcode")
'strFilter = "Postcode between '" & "*" & txtKleur & "*'"
'filterWaarde = ">=" & "B - " & filterStartPostcode & " And " & "<=B - " & filterEindePostcode

Case 2
filterNaam = InputBox("Geef de familienaam of beginletter(s) van de naam", "Naam")

Case 3
filterStartPostcode = InputBox("Geef de beginwaarde van de postcode", "Postcode")
filterEindePostcode = InputBox("Geef de eindwaarde van de postcode", "Postcode")
filterNaam = InputBox("Geef de familienaam of beginletter(s) van de naam", "Naam")

End Select
DoCmd.Echo False
DoCmd.OpenQuery "qryKlantenlijst", , acEdit

strFilter = BuildCriteria("Postcode", dbText, filterWaarde)
Me.FilterOn = True
DoCmd.Close acQuery, "qryKlantenlijst", acSaveYes
DoCmd.Echo True
SendTQ2Excel ("qryKlantenLijst")

Exit_Proc:
Exit Sub

Err_afhandeling:
MsgBox Err.Description
Resume Exit_Proc
End Sub
 
The code is not correct! Before the Me.Filteron=True there is standing Me.Filter=strFilter.
 
You apply filter to wrong form. Try:
[tt]...
strFilter = BuildCriteria("Postcode", dbText, filterWaarde)
Screen.ActiveDatasheet.Filter=strFilter
Screen.ActiveDatasheet.FilterOn = True[/tt]

combo
 
Ok filterOn is working. Thanks.
I can see that the query is filtered but the strange thing is that when Excel opens I got all the data and not the filtered ones. The query is saved with DoCmd.Close acQuery, "qryKlantenlijst", acSaveYes
or not???
 
May I ask you for an example please. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top