Solved

Access report source with date range

Posted on 2014-03-20
8
542 Views
Last Modified: 2014-03-21
I have a ACCESS 2010 subreport with the report source property something like:
Select * from tblNotes where NoteDate > getStartDate()

The function getStartDate() gets date from a form text box:
...
Public Function getWorkloadStartDate() As Date
    'function pair used in srptWorkload, srptCurrentBid etc  record source
    getWorkloadStartDate = Format(Forms!frmWorkLoadPrint_Option.dtpFrom.Value, "yyyy/mm/dd")
End Function

Open in new window


I have also tried ...

Public Function getWorkloadEndDate() As Date
    getWorkloadEndDate = Format(Forms!frmWorkLoadPrint_Option.dtpTo.Value, "yyyy/mm/dd")
End Function
Public Function getWorkloadStartDate2() As Date
    'function pair used in srptCurrentBid etc  record source
    getWorkloadStartDate2 = Format(Forms!frmWorkLoadPrint_Option.dtpFrom.Value, "\#yyyy\-mm\-dd\#")
End Function
Public Function getWorkloadEndDate2() As Date
    getWorkloadEndDate2 = FormatForms!frmWorkLoadPrint_Option.dtpTo.Value, "\#yyyy\-mm\-dd\#")
End Function


Public Function getdCutOffDate() As Date

    getdCutOffDate = CDate(dCutOffDate)
    
End Function

Open in new window


...

My report is almost correct, however one user has noted that it does not pick up one of his notes.  I did some testing and although it works perfectly for most notes, it has an issue with a few notes.
If I hard code the record source to be:
Select * from tblNotes where NoteDate > #20/02/2014#
it collects the correct number of notes, however, if the form textbox is 20/02/2014 it misses one or two notes.

If this was VBA know I could use :
"Select * from Notes where noteDate > #" & format(FromDate "yyyy/mm/dd") & "#"

but how do I replicate this in report record source property box?  (remember it is a SUB report, not a report, so I can't set me.recordsource using VBA on the report open event since master child won't work)

Please note I am in Australia where date format is dd/mm/yyyy, not mm/dd/yyyy.
Also note that I have used yyyy/mm/dd after testing dd/mm/yyyy and mm/dd/yyyy unsuccessfully.
I HATE working with dates!
0
Comment
Question by:MonkeyPie
  • 3
  • 3
  • 2
8 Comments
 
LVL 39

Assisted Solution

by:als315
als315 earned 250 total points
ID: 39944460
You should convert text field from form to Date with:
Datevalue(FormatForms!frmWorkLoadPrint_Option.dtpTo.Value)
Do not use # or Cdate if your date format is not mm/dd/yyyy
You can also use DateSerial function
0
 

Author Comment

by:MonkeyPie
ID: 39944487
Thanks ALS315 but that did not work.  It had exactly the same result as:
getWorkloadStartDate = Format(Forms!frmWorkLoadPrint_Option.dtpFrom.Value, "yyyy/mm/dd")

I also tried "dd/mm/yyyy" again just to check.  Also, only getting 55 out of the 56 notes it finds if I hard code in date.

I added some debug.print lines to check form date "01/03/2014" and resulting date from function (also "01/03/2014") which are both correct.

So, just to confirm if function returns 01/03/2014 as type DATE, this gives a different result to hardcoded record source:
Select * from xx where NoteDate > #01/03/2014#

- where I expect the result to be the same.
0
 

Author Comment

by:MonkeyPie
ID: 39944502
I have done more testing and found this:

If I change the hardcoded recordsource to :

Select * from xx where NoteDate > #03/01/2014#
(switching dd/mm to mm/dd)
I then get the same BAD result as I get with my function.
So, it is obviously to do with swtiching mm and dd around, but I can't work out how to fix it!  Any ideas?
Can I say:
datevalue(format(NoteDate, "dd/mm/yyyy")) > datevalue(format(formDate, "dd/mm/yyyy")?

Seems overly complicated.
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 250 total points
ID: 39944562
Your original query is OK, but the function is not correct as Format returns a string. It shall read:
Public Function getWorkloadStartDate() As Date
    ' Function pair used in srptWorkload, srptCurrentBid etc. record source.
    getWorkloadStartDate = DateValue(Forms!frmWorkLoadPrint_Option!dtpFrom.Value)
End Function

Open in new window

/gustav
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 39

Expert Comment

by:als315
ID: 39945014
Thanks, Gustav.
I hope sometime you will have time to write an article about date values in Access
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39945028
Yes, I've tried a couple of times but too much real work blocks.

/gustav
0
 

Author Closing Comment

by:MonkeyPie
ID: 39946472
Thank you everyone.  Both DateSerial (yy, mm, dd)  and

DateValue(Forms!frmWorkLoadPrint_Option!dtpFrom.Value)

worked.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39946522
You are welcome!

/gustav
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now