Need help in VBA with DSUM and some variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chester64
    New Member
    • Nov 2009
    • 3

    Need help in VBA with DSUM and some variables

    I have a report that i use code to calculate different fields. I want to change the code to accept user dates instead of using static dates. Below is an example of how it is currently.

    DTotal.Value = DSum("[D]", "log", "[TYPE] = 3 AND Date >= #5/1/2008# AND Date <= #4/30/2009#")

    I tried to change it to this (I know that the dates are still static but i just want to get the variables to work correctly first) ...

    Dim StartDate, EndDate As Date
    StartDate = #5/1/2008#
    EndDate = #4/30/2009#

    DTotal.Value = DSum("[D]", "log", "[TYPE] = 3 AND Date >= " & StartDate & " AND Date <= " & EndDate)

    When i run it like this, it returns a blank (or null i guess) value. Can anyone tell me what i am doing wrong?

    Thanks,
    Chester64
  • patjones
    Recognized Expert Contributor
    • Jun 2007
    • 931

    #2
    Try this:

    Code:
    DTotal.Value = DSum("[D]", "log", "[TYPE] = 3 AND Date >= #" & StartDate & "# AND Date <= #" & EndDate & "#")

    The #'s need to be included even though you already explicitly declared StartDate and EndDate to be Dates.

    Pat

    Comment

    • chester64
      New Member
      • Nov 2009
      • 3

      #3
      That worked great!! Thanks!

      Comment

      Working...