Results 1 to 6 of 6
  1. #1
    aaendewy is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2018
    Posts
    6

    UPDATE blank or empty record row

    At the moment I have a form and a button to insert record row into a table.

    However, I want to write another SQL Update query to update record if user did not fill out FirstName field I want to use FirstName data from the previous row.

    For example:

    Row 1:
    John Doe 56 Male

    New insert:
    <EMPTY> Johnstone 65 Male



    I want my new result to be: (Row 2)
    John Johnstone 65 Male

  2. #2
    aaendewy is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2018
    Posts
    6
    What I've got so far is ;

    UPDATE Employee SET Employee.FirstName = PreviousRecord WHERE (((Employee.FirstName) Is Null));

    PreviousRecord is in red, what's the function to fetch previous record data?

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,819
    Suggest a better/easier approach is to use VBA to set textbox DefaultValue property. This is a rather common issue and example code in many threads.

    But why would you want to use a name that might not be valid for the record?

    Either set the field in table as required and let Access nag users or maybe just ValidationRule property of textbox or use VBA to validate record before it is committed. Again, data validation is common topic.
    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.

  4. #4
    aaendewy is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2018
    Posts
    6
    Hi June7, this is just an example of my actual work.

    My actual work is actually updating the "Status" column e.g. if the new entry has empty "Status" text field then the status should be the same as previous.


    Quote Originally Posted by June7 View Post
    Suggest a better/easier approach is to use VBA to set textbox DefaultValue property. This is a rather common issue and example code in many threads.

    But why would you want to use a name that might not be valid for the record?

    Either set the field in table as required and let Access nag users or maybe just ValidationRule property of textbox or use VBA to validate record before it is committed. Again, data validation is common topic.

  5. #5
    jjcalo is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2018
    Location
    Illinois, USA
    Posts
    2
    How about executing an UPDATE statement in the AfterInsert event.

    In this event handler, if the first name is null, then update it with the previous record's firstname.

    And if you have an AutoNumber field, use a DLookup to get the previous record's first name.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,819
    I am confused. Why did you initially reference name data?

    What exactly defines 'previous' entry? Records entered in current session or some record saved on another day?

    Doing a lookup for 'last' record is not as simple as it sounds.
    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.

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

Similar Threads

  1. Update blank records to last record number + 1
    By NicksMovement in forum Queries
    Replies: 1
    Last Post: 08-25-2017, 10:26 AM
  2. Replies: 5
    Last Post: 01-13-2015, 11:57 AM
  3. not print blank pages when a subreport is empty
    By fabiobarreto10 in forum Reports
    Replies: 3
    Last Post: 04-28-2012, 10:01 AM
  4. Blank screen on empty query
    By JackieEVSC in forum Forms
    Replies: 2
    Last Post: 11-29-2011, 03:59 PM
  5. Controls go blank on empty query result
    By kevdfisch in forum Programming
    Replies: 4
    Last Post: 08-25-2009, 08:07 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