Results 1 to 7 of 7
  1. #1
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41

    Report by Date

    hi all, i want to create report from one date in form by vba, but its not working :

    Dim FromDate As String
    FromDate = "1368/10/27"
    DoCmd.OpenReport "Project", acViewReport, , "[Date2]= #" & Format(FromDate, "yyyy/mm/dd") & "#"

    [Date2] field is Short Text type.
    Click image for larger version. 

Name:	date22.png 
Views:	12 
Size:	3.8 KB 
ID:	30527

    can someone provide the correct method to use??


    (Sorry for my poor english)

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Date2 as a string must have quotes, not "#" - those are for date types only. Also for FromDate, which is also a string, you cannot format it as you are doing. Why not just use "Date2='1368/10/27'"?

  3. #3
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    hey,, Thanks for correcting the code,,, i had chosen a wrong way and i didn't know that was so easy.
    but now, how can i create report between tow date ?? for example between 1368/10/27 and 1368/10/29 .

    thanks again.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I'm not sure what those values are, they aren't real dates for Access.

    But the syntax would be:
    Date2 Between #" & date_from & "# AND #" & date_to & "#"

    assuming all three fields are date type.

  5. #5
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    can we use between,and only in date type?
    is there a way to create report between in range of string value??

    my date is persian, but access does not support persian date, for this reason i use string type to field.


    for this my problem i written this code but it is not correct :

    DoCmd.OpenReport "Project", acViewReport, , "[Date2] BETWEEN '1368/10/27'" and '1368/10/29'"

    Any help would be gratefully received.

  6. #6
    Join Date
    Apr 2017
    Posts
    1,792
    When you have your dates as text strings in format "yyyy/mm/dd", then BETWEEN must work (it doesn't work when order of year, month and day is different).

    Try DoCmd.OpenReport "Project", acViewReport, , "[Date2] BETWEEN '1368/10/27' and '1368/10/29'"

  7. #7
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    thank you, If i want to use textbox and enter date to textbox then create report, i must use this code ???? :

    DoCmd.OpenReport "Project", acViewReport, , "[Date2] BETWEEN 'Text_Start' and 'Text_End'"

    (sorry for my poor english)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 15
    Last Post: 12-07-2014, 06:22 AM
  2. Display a From Date and To Date on a report
    By Sprinter72 in forum Reports
    Replies: 1
    Last Post: 11-23-2014, 11:16 AM
  3. Replies: 5
    Last Post: 09-26-2014, 01:40 PM
  4. Replies: 3
    Last Post: 09-23-2013, 10:43 PM
  5. Date Range Report with Multiple Date Fields
    By StevenCV in forum Reports
    Replies: 13
    Last Post: 02-29-2012, 08:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums