I posed this question before, but I'm going to do it again. The following is the original question:
A user is on a record on a form. He/she finds that they no longer want that record in the database. I have a Delete button on the form. When they click the button they think they will delete the record, but I want that record to go to a archive table, and then at the same time I want an email message to come to me to notify me of what is going on. Does anyone know code for this? If no one has code for the whole thing, I would definitely want to know how to send the record to the archive table, when the user clicks the Delete button.
This is the code I got for it:
Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
Dim db As DAO.Database, rst As DAO.Recordset
'Copy Record and Save Record to new table
Set db = CurrentDb
Set rst = db.OpenRecordset("YourArchiveTable"
rst.AddNew
rst!field1 = Me!field1
rst!field2 = Me!field2
rst!field3 = Me!field3
' Note: the fields should correspond to your names
' add as many as you need etc.
rst.Update
rst.Close
db.Close
'Delete record
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
'send e-mail
DoCmd.SendObject acSendNoObject, "", acFormatTXT, "To-you", , , "Deleted a record", "message", True
Exit_Command3_Click:
Exit Sub
Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub
There is one problem with the code, when ran. The following line comes up with an error:
Dim db As DAO.Database, rst As DAO.Recordset
I'm working with a Access 2000 database. Could that be the problem, or do someone know why the code doesn't run correctly. Please help. Thanks.
Jerome
A user is on a record on a form. He/she finds that they no longer want that record in the database. I have a Delete button on the form. When they click the button they think they will delete the record, but I want that record to go to a archive table, and then at the same time I want an email message to come to me to notify me of what is going on. Does anyone know code for this? If no one has code for the whole thing, I would definitely want to know how to send the record to the archive table, when the user clicks the Delete button.
This is the code I got for it:
Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
Dim db As DAO.Database, rst As DAO.Recordset
'Copy Record and Save Record to new table
Set db = CurrentDb
Set rst = db.OpenRecordset("YourArchiveTable"
rst.AddNew
rst!field1 = Me!field1
rst!field2 = Me!field2
rst!field3 = Me!field3
' Note: the fields should correspond to your names
' add as many as you need etc.
rst.Update
rst.Close
db.Close
'Delete record
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
'send e-mail
DoCmd.SendObject acSendNoObject, "", acFormatTXT, "To-you", , , "Deleted a record", "message", True
Exit_Command3_Click:
Exit Sub
Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub
There is one problem with the code, when ran. The following line comes up with an error:
Dim db As DAO.Database, rst As DAO.Recordset
I'm working with a Access 2000 database. Could that be the problem, or do someone know why the code doesn't run correctly. Please help. Thanks.
Jerome