Results 1 to 8 of 8
  1. #1
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245

    #Error, from DFirst Function


    Hey, I have set up my Dfirst function, and I am getting an #Error, I have looked at the reasonings for this and my thinking still doesnt work.
    Here is my SQL. the formula is NetCash...

    Code:
    SELECT
    T1.AccountID, 
    T1.ClientID, 
    T1.ProductID, 
    T1.MonthlyDate, 
    T1.Cash,
     (DFirst("[T1].[Cash]","qryAccountSetup","[T1].[ClientID]=" & [T1].[ClientID] & " And [T1].[MonthlyDate] <=#" & [T1].[MonthlyDate] & "#")) AS NetCash
    
    
    FROM qryAccountSetup AS T1;
    Now I have AccountID, which is Autonumber for the table. If i want to get the file 1 row ahead would define this in the DFirstFunction and get that value?

  2. #2
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    The problem is that the alias is not active within the Dlookup. Pull out the T1s inside the quotes. Try something like this:

    (DFirst("[Cash]","qryAccountSetup","[ClientID]=" & [T1].[ClientID] & " And [MonthlyDate] <=#" & [T1].[MonthlyDate] & "#"))

  3. #3
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    perfect, is there away to get it to lag one date? meaning I set up a prior date or something and have it match that date?

  4. #4
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    If it had an autokey, you could add & "AND [Keyfield] < " & T1.[KeyField]

    Gak, wait a minute, this is a recursive query? No, don't think this will work at all. Create a second query that doesn't have the call to itself, and call that one to calculate the DFirst. Make sure it has an order by clause that getswhat you want.

  5. #5
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    I have another quick question....

    How can I set this up to grab previous value not the sum....

    Code:
    (SELECT SUM(Cash)     
    FROM qryAccountSetup AS T2      
    WHERE T2.ClientID = [qryAccountSetup].ClientID   
    AND T2.MonthlyDate < [qryAccountSetup].MonthlyDate) AS PriorCash
    the syntax worked for the DFirst function. Thanks

  6. #6
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Let me try to put it a different way.

    1) Access does not know any order for records.
    2) Access can't refer to a different record when it's on the current record.

    That means that, when calculating a value on the current record, there aren't any other records (like previous record) to refer to. So, you have to code a subquery that properly calculates what that previous record should/would/could have been.

    If you can calculate the ending value, and you know what the current record's change to that value is, then you can just calculate the difference, and that's the starting value. If not, then you need a subquery.

  7. #7
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    ok, I did some research and came up with a bit of an sql, posted in new thread, to allow future searches... Thanks for your help with this DFirst Function!!

  8. #8
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    good enough!

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

Similar Threads

  1. Error with Replace Function
    By Juan4412 in forum Queries
    Replies: 1
    Last Post: 09-30-2012, 05:48 PM
  2. Combo Box Error Stops Function
    By Phred in forum Forms
    Replies: 3
    Last Post: 01-28-2012, 02:21 PM
  3. Error in Function
    By Alex Motilal in forum Programming
    Replies: 2
    Last Post: 10-11-2011, 06:30 AM
  4. VBA - Using GetObject function - get error.
    By jsbotts in forum Programming
    Replies: 7
    Last Post: 10-10-2011, 07:51 AM
  5. aggregate error due to function
    By boutwater in forum Access
    Replies: 2
    Last Post: 09-26-2011, 03:39 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