Results 1 to 9 of 9
  1. #1
    sloppysly is offline Novice
    Windows 2K Access 2003
    Join Date
    Jun 2009
    Posts
    5

    Command button issue

    I am trying to set up a command button in my form that when clicked will delete the record from my form and append it to an archive table. I have tried doing this via VBA and it works but it takes forever to run. So I have tried to set up a macro to do this, which also works but it requires you to click the button, go to the next record, go back to the desired record and click the button again (works much faster than the VBA code). The macro does the following once clicked it first sets the value of the delete field to delete and then runs the append query then runs the delete query (for records with a value of delete in the delete field). I am not sure why I have to change records and click the button again. Does anyone know of a way to do accomplish this task without changing records. Any help you can provide would be greatly appreciated.



    Thanks,
    Tim

  2. #2
    sloppysly is offline Novice
    Windows 2K Access 2003
    Join Date
    Jun 2009
    Posts
    5
    Here is the VBA code that I had set up if it helps.

    Private Sub Delete_Account_Click()
    On Error GoTo Err_Delete_Account_Click
    Me.delete.Value = "Delete"

    Dim db As DAO.Database
    CurrentDb.Execute "AppendFromUnixUserID", dbFailOnError
    CurrentDb.Execute "DeleteFromUnixUserID", dbFailOnError

    Exit_Delete_Account_Click:
    Exit Sub
    Err_Delete_Account_Click:
    MsgBox Err.Description
    Resume Exit_Delete_Account_Click
    End Sub

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'm more curious why the "VBA" takes so long. How about sharing the SQL for each query with us?

  4. #4
    sloppysly is offline Novice
    Windows 2K Access 2003
    Join Date
    Jun 2009
    Posts
    5
    Here is the append query SQL

    INSERT INTO DeleteTable ( [ACR Number], [Date Requested], [Generic Account], [account location], [Request Type], [resource id], [resource name], [Account Owner Name], [Account Owner Corp ID], [Business Justification], Comments, [Password Length], [Password Composition], [Frequency of Change], Interactivity, [Generic Account Category], [Users of Non-Corp Id], [Last Updated by], [Last Updated], [Delete] )
    SELECT Triage.[ACR Number], Triage.[Date Requested], Triage.[Generic Account], Triage.[account location], Triage.[Request Type], Triage.[Resource ID], Triage.[Resource Name], Triage.[Account Owner Name], Triage.[Account Owner Corp ID], Triage.[Business Justification], Triage.Comments, Triage.[Password Length], Triage.[Password Composition], Triage.[Password Frequency of Change], Triage.Interactivity, Triage.[Generic Account Category], Triage.[Users of Non-Corp Id], Triage.[Last Updated by], Triage.[Last Updated Date], Triage.Delete
    FROM Triage
    WHERE (((Triage.Delete)="Delete"));

    Delete query SQL

    DELETE Triage.[ACR Number], Triage.[Date Requested], Triage.[Generic Account], Triage.[account location], Triage.[Request Type], Triage.[Resource ID], Triage.[Resource Name], Triage.[Account Owner Name], Triage.[Account Owner Corp ID], Triage.[Business Justification], Triage.Comments, Triage.[Password Length], Triage.[Password Composition], Triage.[Password Frequency of Change], Triage.Interactivity, Triage.[Generic Account Category], Triage.[Users of Non-Corp Id], Triage.[Last Updated Date], Triage.Delete
    FROM Triage
    WHERE (((Triage.Delete)="Delete"));

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I assume you know the Delete query can look like:
    DELETE *
    FROM Triage
    WHERE (((Triage.Delete)="Delete"));
    ...I see nothing in the Append query out of the normal. Have you tried running it by itself directly? Using VBA to run it should have *no* effect on the speed.

  6. #6
    sloppysly is offline Novice
    Windows 2K Access 2003
    Join Date
    Jun 2009
    Posts
    5
    i have run the VBA and the speed is ok. But i have the same issue with the VBA as i do with the macro. For the delete to be completed I need to click the button, go to the next record, go back to the record I want deleted and click the button again. I don't understand why I need to go the next record and back, am I missing something in my VBA code.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Aside from the fact that your field/control name is a Reserved Word, the problem you are having is because the current record has not been saved yet. Moving off of the current record saves it.
    Code:
    Private Sub Delete_Account_Click()
       On Error GoTo Err_Delete_Account_Click
       Me.Delete = "Delete"
       DoCmd.RunCommand acCmdSaveRecord
       CurrentDb.Execute "AppendFromUnixUserID", dbFailOnError
       CurrentDb.Execute "DeleteFromUnixUserID", dbFailOnError
    Exit_Delete_Account_Click:
       Exit Sub
    Err_Delete_Account_Click:
       MsgBox Err.Description
       Resume Exit_Delete_Account_Click
    End Sub

  8. #8
    sloppysly is offline Novice
    Windows 2K Access 2003
    Join Date
    Jun 2009
    Posts
    5
    Thanks RuralGuy once i put in the save command it worked instantanously with no issues I appreciate the help.

    Tim

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad I could help. So this thread is solved? Marking SOLVED is one of the thread tools.

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

Similar Threads

  1. Adding Command Button To Form
    By uneek78 in forum Forms
    Replies: 7
    Last Post: 03-27-2009, 07:43 PM
  2. Duplicate command button
    By brettg in forum Database Design
    Replies: 1
    Last Post: 08-04-2008, 04:16 AM
  3. Command button code
    By lfolger in forum Forms
    Replies: 3
    Last Post: 03-25-2008, 04:26 PM
  4. Command button for time & date
    By joet5402 in forum Forms
    Replies: 2
    Last Post: 12-20-2007, 02:59 AM
  5. command button to filter a subform issue -
    By countdrako in forum Forms
    Replies: 1
    Last Post: 12-09-2005, 11:58 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