Results 1 to 4 of 4
  1. #1
    rwahdan@gmail.com is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2015
    Posts
    28

    Exclamation looping to delete records


    Hi,

    I am trying to delete records from table when closing the form. I have the code but not sure where i went wrong?

    Code:
    Set rst1 = db1.OpenRecordset("SELECT * FROM grade4MultiAnswers")
        
        rst1.MoveFirst
        Do Until rst1.EOF
        rst1.Edit
        rst1!theanswer = ""
        rst1!iscorrect = 0
        
        rst1.MoveNext
        rst1.Update
        Loop
    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Your code is not deleting records from form. It is editing data of a recordset object.

    Update before MoveNext
    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
    Minty is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    Why loop at all? One update query would achieve this;

    Code:
    Dim sSql as string
    
    sSql = "UPDATE  grade4MultiAnswers SET theanswer = '', iscorrect = 0 "
    
    currentdb.execute sSql, dbSeechanges
    
    
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    As others have said, you are not deleting records.
    You are updating a table.
    You should review basic SQL query types.

    SQL will do the job quite efficiently as Minty suggests.

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

Similar Threads

  1. Split form and looping within records
    By jaryszek in forum Access
    Replies: 1
    Last Post: 11-13-2017, 05:24 AM
  2. Help with Looping Records
    By jtm013 in forum Programming
    Replies: 7
    Last Post: 04-30-2015, 01:39 PM
  3. do Loops - Not looping thru all records
    By kfschaefer1 in forum Programming
    Replies: 1
    Last Post: 03-27-2014, 11:42 PM
  4. Looping through records in a continous form
    By accessnihon in forum Forms
    Replies: 3
    Last Post: 01-04-2012, 01:04 AM
  5. Looping through Records in SQL
    By make me rain in forum Queries
    Replies: 13
    Last Post: 07-17-2011, 08:58 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