Jack, here's what I do. This assumes referential integrity with cascading
deletes.
It also assumes tblOrders and tblUnCommissioned are exactly the same
structure with identical field names.
You may have to fiddle with this to match them up as you indicated that the
autonumber is missing in one table.
You will need to adjust the WHERE sql clauses to match your form.
You may also need to change the original detail.backcolor. Mine is 16777088.
HTH, UpRider
Private Sub cmdDelete_Click()
dim intMsgBox as Integer
Dim strSQL As String
On Error GoTo err_cmdDelete_Click
Me.Detail.BackColor = vbRed
intMsgBox = MsgBox("Here's what happens when you delete an order:" &
vbCrLf _
& "1. The order is deleted from this screen." & vbCrLf _
& "2. Any payments against this order are deleted." & vbCrLf _
& "3. This invoice number will be added to the Deleted Invoice
Report, " _
& " along with your explanation in the Notes box.", _
vbOKCancel + vbCritical, "D E L E T E T H I S O R D E R")
If intMsgBox = vbCancel Then
Me.Detail.BackColor = 16777088
Exit Sub
End If
Dim db As dao.Database
Set db = CurrentDb
'copy the record from tblOrders to tblUnCommissioned
strSQL = "INSERT INTO tblUnCommissioned " _
& "Select * from tblOrders " _
& "WHERE (((tblOrders.InvoiceNo)=" &
[Forms]![frmOrders]![txtInvoiceNo] & "));"
db.Execute strSQL, dbFailOnError
'delete the record in tblOrders
strSQL = "DELETE tblOrders.InvoiceNo FROM tblOrders " _
& "WHERE (((tblOrders.InvoiceNo)= " &
[Forms]![frmOrders]![txtInvoiceNo] & "));"
db.Execute strSQL, dbFailOnError
Set db = Nothing
Me.Requery
err_cmdDelete_Click_Exit:
Me.Detail.BackColor = 16777088
DoCmd.GoToRecord , , acFirst
Exit Sub
err_cmdDelete_Click:
If Err = 3200 Then
MsgBox "This invoice has payments posted. If you wish to delete the
order, " _
& "you must delete all the payments first.", vbOKOnly +
vbCritical, _
"U N A B L E T O D E L E T E"
GoTo err_cmdDelete_Click_Exit
End If
' If Err = 2046 Then
' GoTo err_cmdDelete_Click_Exit
' End If
MsgBox "Delete Error " & Err & Err.Description, vbOKOnly, "D E L E T E
E R R O R"
GoTo err_cmdDelete_Click_Exit
End Sub