Results 1 to 6 of 6
  1. #1
    Cafe2UEMP is offline Novice
    Windows 10 Access 2007
    Join Date
    Nov 2017
    Posts
    8

    Syntax issue with Function

    Hi



    I am trying to create a function to compare sales to date in this financial year compared with last financial year.

    My function to get this years result is:

    Public Function FinYTDCash() As Currency
    Dim EndDate As Date
    Dim StartDate As Date
    Dim ThisYear As Integer


    ThisYear = Year(Date)
    EndDate = (Date)
    StartDate = DateSerial(Year(Date), 7, 1)


    FinYTDCash = DSum("[Cash]", "QrySalesFiscalandCal", "[date1] BETWEEN #" & StartDate & "# AND #" & EndDate & "# " And _
    "[FY] = '" & ThisYear & "'")


    End Function

    Each criteria works individually but not when I combine them leading me to think the syntax is wrong.

    Any assistance would be greatly appreciated.

    Thanks

    David

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Let's look at the 3rd argument:
    "[date1] BETWEEN #" & StartDate & "# AND #" & EndDate & "# " And _
    "[FY] = '" & ThisYear & "'")
    ...removing the line continuation...
    "[date1] BETWEEN #" & StartDate & "# AND #" & EndDate & "# " And "[FY] = '" & ThisYear & "'"
    see anything wrong?

  3. #3
    Cafe2UEMP is offline Novice
    Windows 10 Access 2007
    Join Date
    Nov 2017
    Posts
    8
    Quote Originally Posted by RuralGuy View Post
    Let's look at the 3rd argument:
    "[date1] BETWEEN #" & StartDate & "# AND #" & EndDate & "# " And _
    "[FY] = '" & ThisYear & "'")
    ...removing the line continuation...
    "[date1] BETWEEN #" & StartDate & "# AND #" & EndDate & "# " And "[FY] = '" & ThisYear & "'"
    see anything wrong?

    Sorry but no. I still cannot see the problem

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Ranman is pointing out that your use of the & and AND aren't escaped correctly. The DSum should be
    Code:
    DSum("[Cash]", "QrySalesFiscalandCal", "[date1] BETWEEN #" & StartDate & "# AND #" & EndDate & "#  And [FY] = " & ThisYear )
    Note that this year is an integer so I've removed the quotes around it.

  5. #5
    Cafe2UEMP is offline Novice
    Windows 10 Access 2007
    Join Date
    Nov 2017
    Posts
    8
    Quote Originally Posted by Minty View Post
    Ranman is pointing out that your use of the & and AND aren't escaped correctly. The DSum should be
    Code:
    DSum("[Cash]", "QrySalesFiscalandCal", "[date1] BETWEEN #" & StartDate & "# AND #" & EndDate & "#  And [FY] = " & ThisYear )
    Note that this year is an integer so I've removed the quotes around it.
    Thanks for this. Unfortunately, it still produces a syntax error

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Copy and paste EXACTLY what you have please.

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

Similar Threads

  1. DAvg Syntax with Between function
    By Rickochezz in forum Queries
    Replies: 5
    Last Post: 03-12-2017, 01:40 PM
  2. Right Function SQL syntax help
    By hellfire45 in forum Access
    Replies: 9
    Last Post: 04-07-2015, 11:48 AM
  3. syntax issue when searchin dates
    By mike02 in forum Programming
    Replies: 1
    Last Post: 07-10-2013, 10:09 AM
  4. Function Syntax
    By RayMilhon in forum SQL Server
    Replies: 4
    Last Post: 03-15-2013, 01:40 PM
  5. IIF function syntax
    By kris335 in forum Access
    Replies: 5
    Last Post: 09-13-2011, 11:14 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