applying a filter to report (1 Viewer)

smig

Registered User.
Local time
Today, 15:27
Joined
Nov 25, 2009
Messages
2,209
I'm trying to apply a filter to report OnOpen. and something is getting wrong :banghead:
I keep getting an error message:
2101 - Setting a wrong property

Code:
Private Sub Report_Open(Cancel As Integer)

Dim strFilter As String

strFilter = "[LakoachID] = " & GetLakoachID() & " OR [LakoachRashiID] = " & GetLakoachID() & " OR [LakoachID] = 11615 "

Me.Filter = strFilter
Me.FilterOn = True

End Sub

the GetLakoachID() exist and return a long var

this will return the same error
strFilter = "[LakoachID] = 11615 OR [LakoachRashiID] = 11615 OR [LakoachID] = 11615 "
 

isladogs

MVP / VIP
Local time
Today, 13:27
Joined
Jan 14, 2017
Messages
18,211
You have used the same field twice
Code:
strFilter = "[LakoachID] = 11615 OR [LakoachRashiID] = 11615 [B][COLOR="Red"]OR [LakoachID] = 11615 [/COLOR][/B]"

Also FWIW, you have a space at the end & the [] aren't required ...but neither are causing any issues here
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:27
Joined
May 21, 2018
Messages
8,527
are both [LakoachID] and [LakoachRashiID] defined as numeric fields at that table level?
 

smig

Registered User.
Local time
Today, 15:27
Joined
Nov 25, 2009
Messages
2,209
You have used the same field twice
Code:
strFilter = "[LakoachID] = 11615 OR [LakoachRashiID] = 11615 [B][COLOR="Red"]OR [LakoachID] = 11615 [/COLOR][/B]"

Also FWIW, you have a space at the end & the [] aren't required ...but neither are causing any issues here

I know i used the same ID twice.
It was just for a test

I also tried without the []
 

isladogs

MVP / VIP
Local time
Today, 13:27
Joined
Jan 14, 2017
Messages
18,211
What is the code for the function GetLakoachID?

Also perhaps you have some corruption. Try decompiling your DB
 

smig

Registered User.
Local time
Today, 15:27
Joined
Nov 25, 2009
Messages
2,209
even if I try Me.Filter = "" I get the same error :(
 

June7

AWF VIP
Local time
Today, 04:27
Joined
Mar 9, 2014
Messages
5,468
Agree, apply filter in OpenReport method instead of trying to filter report in Open event.
 

smig

Registered User.
Local time
Today, 15:27
Joined
Nov 25, 2009
Messages
2,209
I can't use the Docmd.OpenReport,as this is a Sub report
 

smig

Registered User.
Local time
Today, 15:27
Joined
Nov 25, 2009
Messages
2,209
If nothing works I'll modify the recordSource instead
 

bastanu

AWF VIP
Local time
Today, 05:27
Joined
Apr 13, 2010
Messages
1,402
Try to use the master/child to link it to the main report or apply the where clause to its record source.
 

isladogs

MVP / VIP
Local time
Today, 13:27
Joined
Jan 14, 2017
Messages
18,211
Compacting rarely helps with this type of issue.
Decompiling often works which is why I suggested that!

I also asked about your function
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:27
Joined
Jul 9, 2003
Messages
16,278
In your Subreport property sheet, have you manually cleared the filter? Have you also manually set the "Filter On Load" to"NO"
 

Users who are viewing this thread

Top Bottom