Senin, 24 Februari 2014

RE: [MS_AccessPros] Create Delete button that archives the record you have open in the form

 

I like the idea of it being a date so that you can timestamp when it was archived.  You can then check for null values if it hasn’t.

 

From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of John Viescas
Sent: Monday, February 24, 2014 1:58 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Create Delete button that archives the record you have open in the form

 



Dale-

 

This is much easier to do in VBA.

 

Private Sub cmdDelete_Click()

Dim db As DAO.Database

    ' Set an error trap

    On Error GoTo Delete_Fail

    ' Make sure focus is not on the "new" record

    If Me.NewRecord Then

        MsgBox "You cannot click Delete when you have selected the 'new' record."

        Exit Sub

    End If

    If vbYes = MsgBox("Are you sure you want to delete " & _

       Me.FirstName & " " & Me.LastName & "?", _

        vbQuestion + vbYesNo + vbDefaultButton2) Then

        ' First copy the record

        Set db = CurrentDb

        db.Execute "INSERT INTO DeleteMainArchive " & _

            "( <list all field names here > ) VALUES(" & _

            <insert values from current record in the same sequence as the field list> & _

            < be sure to put quotes ' around text values and # around date/time values > & ")"" & _

            , dbFailOnError

        ' Now delete the record

        RunCommand acCmdSelectRecord

        RunCommand acCmdDelete

    End If

 

Done:

    Set db = Nothing

    Exit Sub

 

Delete_Fail:

    MsgBox "Unexpected error: " & Err & ", " & Error

    Resume Done

End Sub

 

John Viescas, Author

Microsoft Access 2010 Inside Out

Microsoft Access 2007 Inside Out

Microsoft Access 2003 Inside Out

Building Microsoft Access Applications 

SQL Queries for Mere Mortals 

(Paris, France)

 

 

 

On Feb 24, 2014, at 8:52 PM, <tenn_tazz26@yahoo.com> <tenn_tazz26@yahoo.com> wrote:



I am using MS Access 2007 and I am trying to figure out how to make a delete button in a form that when a user clicks on it, it will confirm if they wish to delete the record and in the prompt it will show the records FirstName and LastName field, and when they click to confirm the deletion that behind the scenes it will copy that record to an archive table before deleting it from the main table. The form name I am using is called MainForm and the table that is storing the data is called Main. The archive table I created is a copy of the Main table structure and I called it DeleteMainArchive. I thought of using a Macro in combination with an append query but never could figure out how to make the query capture the current record rather then all records.

 

Thanks,

Dale

 






This email (and all attachments) is for the sole use of the intended recipient(s) and may contain privileged and/or proprietary information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (4)
.

__,_._,___

Tidak ada komentar:

Posting Komentar