Results 1 to 5 of 5
  1. #1
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287

    Grabbing a value from a previous record to use a default value in a new record

    Hey guys,

    I am trying to pull a value from the most recent record and use it in a control in the form, so it can be used for a calculation. I highlighted the fields that I am talking about. The top grid is a subform based of the master table, and the bottom boxes are all unbound. VBA is used to push the values to a new record.

    Click image for larger version. 

Name:	stumped.jpg 
Views:	13 
Size:	194.7 KB 
ID:	14811
    Here is the DLookUp code that I am trying to use
    Code:
    =DLookUp("Draw","TABLE_PayrollData","PPE = " & DateAdd("d",-14,[Forms]![MainMenu]![search ppe]) And "Employee = " & [SelectEmp])
    [Forms]![MainMenu]![search ppe] is on the main switchboard, and populates the locked date field right below "Store 08" on the bottom left.



    I want to pull the Draw field from TABLE_PayrollData where PPE (pay period ending date) is the most recent one before the selected from [Forms]![MainMenu]![search ppe] and since all employees are in the same table, I need the employee chosen in the drop down to match the one in the record I am grabbing.

    Thanks guys!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Try:

    =DLookUp("Draw","TABLE_PayrollData","PPE = #" & DateAdd("d",-14,[Forms]![MainMenu]![search ppe]) & "# And Employee = " & [SelectEmp])

    Assumes Employee is a number type field and [SelectEmp] is name of combobox with a number value.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Example Employee number is RR82390. They are saved as a text field in the table. In the screen grab, the field directly below "Ralph Russo" is linked to the bound column in the combo box. That is the Employee number.

    Getting #Error with the changes you suggested.

    Before any changes were made, the the dlookup pulled the first Draw value in the master table. That's where that "96.3674" came from. Seemed like Dlookup just ignored all of the criteria. The date nor the salesperson matched up.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,623
    Text field criteria need apostrophe delimiter (just as the date needed #)

    & "# And Employee = '" & [SelectEmp] & "'")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Oh heck yes! June7 you rock.

    Dlookup is such a pain. I can never get it right.

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

Similar Threads

  1. Replies: 7
    Last Post: 07-20-2013, 03:59 AM
  2. Replies: 8
    Last Post: 07-06-2013, 05:13 PM
  3. Replies: 5
    Last Post: 06-16-2013, 05:25 PM
  4. Replies: 22
    Last Post: 06-12-2012, 10:02 PM
  5. Replies: 2
    Last Post: 06-05-2012, 08:31 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