Results 1 to 6 of 6
  1. #1
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47

    delete multiple records at once


    I have a database with a form that is linked to one table and a subform linked to another table. In the subform there is a field called "DeleteRecord" and is a checkbox. What i am trying to do is create a delete button that deletes all the records in the proper table that have the field checks. I have tried finding the problem in the code but cant seem to find it. The way it is supposed to work is it looks at if the "DeleteRecord" box is checked, and if it is, then it looks to make sure the Owner for the record matches the current user, who logins in w/ his owner name. If they are equal, all checked records for that owner are deleted.

    Any ideas?

    Private Sub Command22_Click()


    Set rst = CurrentDb.OpenRecordset("ResourceAllocation")


    Do Until rst.EOF
    If ResourceAllocation.[DeleteRecord] = True And ResourceAllocation.[Owner] = Owners.[Owner Name] Then
    DoCmd.RunMacro "delete"
    End If

    rst.MoveNext
    Loop

    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Try (no recordset and no loop code):

    CurrentDb.Execute "DELETE FROM ResourceAllocation WHERE DeleteRecord=True AND Owner = '" & Me![Owner Name] & "'"

    What is Owners.[Owner Name] - is it an open form and a control that has the logged in owner name?

    Why do you need to delete records? Why not just tag them as Active/Inactive and filter on this attribute?
    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
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    That gave me the following error :

    Run-time error '3464':
    Data type mismatch in criteria expression

  4. #4
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    and yes, owners.owners name is an open form. The way it works is when the db opens, you are asked for a login, and based on the login, the owner's name is auto populated and shows all resourceallocation records where his name is the value for the Owner field in the ResourceAllocation table.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Owner and Owner Name are both text fields? Or is Owner Name a text or combobox name reference?

    Do you want to provide project for analysis? Follow instructions at bottom of my post.
    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.

  6. #6
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    Im working on getting the sample to put up here. i had the code wrong. owner name was the label for the combo box. I changed it to me.combo10.column(1) which is where the value is from and i still get the same error

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

Similar Threads

  1. Replies: 5
    Last Post: 01-24-2012, 06:19 PM
  2. Replies: 2
    Last Post: 01-24-2012, 02:16 PM
  3. Delete Records
    By dkeeper09 in forum Access
    Replies: 4
    Last Post: 10-28-2011, 01:41 PM
  4. Delete all records
    By stryder09 in forum Access
    Replies: 6
    Last Post: 05-11-2011, 02:07 PM
  5. delete records
    By fiamma68 in forum Queries
    Replies: 0
    Last Post: 11-15-2010, 06:54 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