Results 1 to 5 of 5
  1. #1
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329

    Carry the last record over

    Hi Guy's i am not sure what's going on with me, i know you can't help on that one but this so simple procedure should be simple to my standards even!!

    I am trying to carry over in the example in the image 19.4 from MSNo 4746 to MSNo 4747

    So this is changed on StartTime Update

    Example of carrying over



    Click image for larger version. 

Name:	Capture.JPG 
Views:	17 
Size:	26.5 KB 
ID:	45733

    StartTime AfterUpdate

    Code:
    Dim LastNo As Integer, HoursLeft As Variant, myDriver As StringDim myStart As Date, myEnd As Date
    
    
    myDriver = Me.Driver
    
    
    
    
    If Not IsNull(LastNo = DMax("MSNo", "tblDriverHours", "[Driver] = '" & myDriver & "'")) Then
    LastNo = DMax("MSNo", "tblDriverHours", "[Driver] = '" & myDriver & "'") - 1
    HoursLeft = DLookup("HoursLeft", "tblDriverHours", "[MSNo] = " & LastNo)
    Me.HoursLeft = HoursLeft
    
    
    End If

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You haven't said what the problem is (error, wrong result, etc). Do you know how to set a breakpoint and check the values being returned at each step? If not:

    http://www.baldyweb.com/Debugging.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    If MSNo is an autonumber field (and even if it is a custom counter that you increment yourself) I would not rely on simply substracting 1 to get the previous record; I would use a Top 1 select statement to get the MSNo < Me.MSNo sorted descending on MSNo. Also you declare the LastNo as Integer, should be long as it will error out soon. And you don't show us the Driver field, you treat it as a text (string), if it is a numeric driver ID you don't need the single quotes.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,329
    Hi Guy's yes sorry should have siad MSNo is Not autonumber, ahhhhh just noticed i have it set as text, sorry chap's i think i need to regroup my mind

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    No worries Dave! Still, if you delete a row and have a gap in your MSNo sequence your subtraction logic will fail so you should go with the ordered recordset to get the previous value.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Carry over data question
    By pncbiz in forum Forms
    Replies: 2
    Last Post: 07-27-2020, 01:47 PM
  2. Replies: 6
    Last Post: 07-31-2015, 12:03 PM
  3. Replies: 8
    Last Post: 01-13-2015, 10:27 PM
  4. Continuous Form Carry Over
    By Jrzy3 in forum Forms
    Replies: 2
    Last Post: 11-06-2013, 10:54 AM
  5. Carry value over to new record w/macro
    By bbrazeau in forum Programming
    Replies: 5
    Last Post: 10-27-2011, 09:00 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