Results 1 to 4 of 4
  1. #1
    jbone is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    8

    how to update latest record in table - specific fields

    hello everyone,

    I have an application that I built that allows a user to submit Case information in a form to a table and then they would update them in another form tab. The Case number remains the same and they are allowed to submit new Cases (using the same Case number) given that the most recent one was "closed" - updated with the latest information. Right now, I have an update query that I created that updates all cases with the information in a form but I just want it to update the most recent one because each Case should have different information for each line.

    here is how the SQL view looks like from my query. I hope it can shed some light on how it functions:

    UPDATE table1 SET table1.[Resolution Date] = [Forms]![Main Window]![UpdateRecords]![Text23], table1.[number of inadequate response] = [Forms]![Main Window]![UpdateRecords]![Text21]
    WHERE ((([table1]![ITnumber/Email])=[Forms]![Main Window]![UpdateRecords]![Text15]));

    So I want it to look something like:
    *my notes



    UPDATE table1 SET *the most recent Case field resolution date to* table1.[Resolution Date] = [Forms]![Main Window]![UpdateRecords]![Text23], *the most recent Case field(# of inadequate response)* table1.[number of inadequate response] = [Forms]![Main Window]![UpdateRecords]![Text21]
    WHERE ((([table1]![ITnumber/Email])=[Forms]![Main Window]![UpdateRecords]![Text15]));

    or VBA code

    I appreciate any help with this!

    thank you! 

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    It appears from you description that you have multiple records in table1 with the same case number, but with no way of distinguishing between them. You need another field in the table to indicate the "line number" for each case. Your where clause would then specify case number and line number.

    PS - You really should give your form controls meaningful names, not Text15, Text23 etc. It makes reading the code a lot easier.

  3. #3
    jbone is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    8
    Hey John G,

    thanks for for your reply and suggestion. You are right but I am wondering if I can use the dlast function to update the latest case?

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    No, I don't think so. DFirst and DLast don't order according to the data you request, they use whatever order Access chooses to use for the table or query. You can use criteria to limit the record set that is searched, nothing but beyond that.

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

Similar Threads

  1. Replies: 7
    Last Post: 05-28-2015, 11:43 AM
  2. update specific record from excel
    By kamils48 in forum Access
    Replies: 1
    Last Post: 01-21-2015, 12:54 PM
  3. Replies: 1
    Last Post: 09-04-2013, 03:29 PM
  4. Replies: 4
    Last Post: 03-06-2013, 06:55 AM
  5. Replies: 1
    Last Post: 07-06-2012, 05:32 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