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
> Filter Recordset By Date Using Vba, Access 2010    
 
   
JanRaven
post Jun 23 2019, 11:32 AM
Post#1



Posts: 9
Joined: 22-March 19



Hi everyone.

I would like to filter a recordset by date criteria. The code below works fine if I just type a full date, like so: 2017-10-10, but I would also like to be able to type just a year and would like Access to return all the records that contain that year, say: 2017.
How can I do that?

CODE
SQL = "SELECT * " _
    & "FROM tbMCR " _
    & "WHERE [Scrap Date] = #" & Me.txtScrapDate & "# "
    
Me.sfrmMCR.Form.RecordSource = SQL
Me.sfrmMCR.Requery


As always, any help greatly appreciated smile.gif
Go to the top of the page
 
theDBguy
post Jun 23 2019, 12:06 PM
Post#2


Access Wiki and Forums Moderator
Posts: 75,777
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Welcome to UtterAccess!
welcome2UA.gif

Are you asking how to enter only a Year sometimes and a Full Date other times? Otherwise, if you only want to enter a year all the time, you could try something like this:
CODE
& " WHERE [Scrap Date] Between DateSerial(" & Me.txtYear & ",1,1) And DateSerial(" & Me.txtYear & ",12,31)"

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
JanRaven
post Jun 23 2019, 02:59 PM
Post#3



Posts: 9
Joined: 22-March 19



Thank you.
That's exactly what I wanted. Works like a charm smile.gif
Go to the top of the page
 
theDBguy
post Jun 23 2019, 03:15 PM
Post#4


Access Wiki and Forums Moderator
Posts: 75,777
Joined: 19-June 07
From: SunnySandyEggo


Hi. You're welcome. Glad we could assist. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    23rd July 2019 - 02:48 AM