Results 1 to 3 of 3
  1. #1
    Perfac's Avatar
    Perfac is offline Expert
    Windows 7 64bit Access 2016
    Join Date
    May 2016
    Location
    Centurion Pretoria
    Posts
    618

    Variables

    The following code gave me this error: "Run-time error '2471': The expression you have entered as a query parameter produced this error:'dStartDate'"


    Dim cStartAmount As Currency


    Dim dDocumentDate As Date
    Dim dStartDate As Date
    Dim dEndDate As Date
    dStartDate = Me.txt_startdate '01-Mar-17
    dEndDate = Me.txt_enddate '01-Mar-50
    dDocumentDate = DLookup("[DocumentDate10]", "t03SalSumMnth", "t03salsummnth.SlSmMnID=" & 1)
    cStartAmount = DLookup("[StartAmount]", "t02PAYE", "#" & Format([dDocumentDate], "yyyy-mm-dd") & "# Between dStartDate And dEndDate")

    What I'm trying to accomplish is to find "[StartAmount]" fields value where dDocumentDate is bigger than dStartDate and smaller than dEndDate

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Try this

    Code:
    cStartAmount = DLookup("[StartAmount]", "t02PAYE", "dStartDate < #" & Format([dDocumentDate], "yyyy-mm-dd") & "# And dEndDate > #" & Format([dDocumentDate], "yyyy-mm-dd") & "#"))
    Last edited by isladogs; 04-06-2018 at 09:31 AM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    John_G is offline VIP
    Windows 10 Access 2016
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    What are dStartDate and dEndDate? In the context you are using them, they would have to be fields in the table/query t02PAYE.

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

Similar Threads

  1. Variables In VBA
    By jo15765 in forum Programming
    Replies: 4
    Last Post: 12-15-2016, 08:19 AM
  2. Variables In VBA
    By jo15765 in forum Programming
    Replies: 3
    Last Post: 11-01-2016, 08:26 AM
  3. VBA variables in SQL
    By compooper in forum Programming
    Replies: 3
    Last Post: 07-06-2011, 11:04 AM
  4. VBA in variables
    By smikkelsen in forum Access
    Replies: 3
    Last Post: 11-12-2010, 03:14 PM
  5. sql in vb variables
    By emilylu3 in forum Programming
    Replies: 3
    Last Post: 03-04-2006, 01:26 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