UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Form Filter, Access 2010    
 
   
dzoker
post Jun 2 2020, 02:26 PM
Post#1



Posts: 478
Joined: 12-February 14



Hi All,

How do I filter a form (bound to a table) using vba by using a date field from the table? I need to only see records within the last 365 days?

ty

P.P. I know I can bound the form to a query and do it that way (even vba) but I was wondering with a table.
Go to the top of the page
 
tina t
post Jun 2 2020, 02:32 PM
Post#2



Posts: 6,692
Joined: 11-November 10
From: SoCal, USA


try

Me.Filter = "MyDateFieldName > #" & Date - 366 & "#"
Me.FilterOn = True

or

Me.Filter = "MyDateFieldName > #" & DateAdd("d", - 366, Date) & "#"
Me.FilterOn = True

hth
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
GroverParkGeorge
post Jun 2 2020, 02:33 PM
Post#3


UA Admin
Posts: 37,513
Joined: 20-June 02
From: Newcastle, WA


You can use the form's Filter to do this:
CODE
Private Sub filterme()

    Dim dtFilter As Date
    
    dtFilter = DateAdd("yyyy", -1, Date)
    With Me
        .Filter = "YourDateFieldGoesHere = " & dtFilter
        .FilterOn = True
    End With
    
End Sub

--------------------
My Real Name Is George. Grover Park Consulting is where I did business for 20 years.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
dzoker
post Jun 2 2020, 03:07 PM
Post#4



Posts: 478
Joined: 12-February 14



tina & GroverParkGeorge,

Thank you both!!! both work!
Go to the top of the page
 
tina t
post Jun 2 2020, 04:42 PM
Post#5



Posts: 6,692
Joined: 11-November 10
From: SoCal, USA


George, am i reading right that your filter will pull records only with date one year ago today? tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    14th July 2020 - 03:53 AM