Connecting Tech Pros Worldwide Forums | Help | Site Map

Retrieve records two dates (MS ACCESS)

Newbie
 
Join Date: May 2008
Posts: 2
#1: Apr 3 '09
I design a report that will show all the records for a particular client and all the records do show in the report BUT when I try to search between dates than only half of the records are showing ....... records in the middle of the date range are missing and EndDate records also doesn't show. I use the following code on the OnClick Event of the OK button on my form
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command4_Click()
  2. On Error GoTo Err_Command4_Click
  3. Dim stCriteria As String
  4. Dim stDocName As String
  5. stLinkCriteria = "([ClientNr]=" & Me.ClientNr & ") AND ([Date] Between #" & Me.BeginDate & "# AND #" & Me.EndDate & "#)"
  6. stDocName = "PersAmendmentMovByDate"
  7. DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
  8. Exit_Command4_Click:
  9. Exit Sub
  10. Err_Command4_Click:
  11. MsgBox Err.Description
  12. Resume Exit_Command4_Click
  13. End Sub

NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#2: Apr 3 '09

re: Retrieve records two dates (MS ACCESS)


Almost certainly because the dates aren't treated consistently as dates.

A string with a formatted date in it will sort as a string, and not a date.

Does that help?

Welcome to Bytes!
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#3: Apr 3 '09

re: Retrieve records two dates (MS ACCESS)


PS. "#" characters are needed for dates it's true, but it not quite as simple as that. See Literal DateTimes and Their Delimiters (#) for the full lowdown. Particularly about formatting the date into SQL standard format to use in SQL.
Reply


Similar Microsoft Access / VBA bytes