Results 1 to 4 of 4
  1. #1
    David Randle is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    6

    MS Access Date Variables in Dsum

    Hi

    I am trying to use date variables in an expression for dsum but cannot get the syntax correct.

    I have

    Public Function Cash1() As Currency
    Dim StartDate As Date
    Dim EndDate as Date


    StartDate = Forms!FrmDates!StartDate
    EndDate = Forms!FrmDates!EndDate


    Cash1 = DSum("[Cash]", "QrySalesByDate", "[date1] between #" & StartDate & " # " and #" & EndDate & " # ")
    End Function

    Can anyone tell me what I am doing wrong?

    Many thanks

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Looks like you have a quote in the wrong place and too many spaces ..

    Try
    Code:
    Public Function Cash1() As Currency
        Dim StartDate As Date
        Dim EndDate As Date
        StartDate = Forms!FrmDates!StartDate
        EndDate = Forms!FrmDates!EndDate
    
        Cash1 = DSum("[Cash]", "QrySalesByDate", "[date1] BETWEEN #" & StartDate & "# AND #" & EndDate & "# ")
    
    End Function

  3. #3
    David Randle is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    6
    Thanks very much, worked perfectly.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Happy to help......

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

Similar Threads

  1. Replies: 2
    Last Post: 03-30-2015, 09:12 AM
  2. How to Format Date parameter in Dsum
    By misahil in forum Queries
    Replies: 3
    Last Post: 09-28-2014, 11:31 AM
  3. Find Variables closest to specified Date
    By crimedog in forum Reports
    Replies: 1
    Last Post: 01-30-2014, 11:10 AM
  4. Using date variables from table in query
    By Skybeau in forum Access
    Replies: 1
    Last Post: 12-22-2011, 08:46 PM
  5. Replies: 5
    Last Post: 06-10-2010, 05:46 PM

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