Kim, you can do it BUT:
The routine will actually insert the new record and details. If the user
changes his mind, he will have to DELETE the order.
Below is the code that works for tables in my order entry/invoicing
database. I don't actually use this code, I came up with it as an
exercise and possible solution for your problem.
The idea is to insert a new record in the Orders table, then copy all the
detail records for the old order back into the detail table, but with the
FK of the new OrderID.
Add a hidden textbox txtOldOrderID.
Code assumes the old order is displayed in the form and the below command
button on that form is clicked.
Good luck,
UpRider
Private Sub cmdCopyOrder_Click()
Dim strSQL As String
Dim rstran As DAO.Recordset
Dim rsobj As DAO.Recordset
txtOldOrderID = [OrderID]
'copy the order back into the Orders table
strSQL = "INSERT INTO tblOrders (LastChanged, DateCreated, CustomerID,
ShipperID, CustPOnum, InvoiceNo, OrderDate, RequiredDate, ShippedDate,
Freight, OrderProdTot, OrderNotes, CategoryID, EmployeeID,
ShipperTracking, OrderIncomplete, TranType ) " _
& "SELECT tblOrders.LastChanged, tblOrders.DateCreated,
tblOrders.CustomerID, tblOrders.ShipperID, tblOrders.CustPOnum,
tblOrders.InvoiceNo, tblOrders.OrderDate, tblOrders.RequiredDate,
tblOrders.ShippedDate, tblOrders.Freight, tblOrders.OrderProdTot,
tblOrders.OrderNotes, tblOrders.CategoryID, tblOrders.EmployeeID,
tblOrders.ShipperTracking, tblOrders.OrderIncomplete, tblOrders.TranType "
_
& "From tblOrders " _
& "WHERE (((tblOrders.OrderID)= " &
[Forms]![frmOrdersMain]![txtOldOrderID] & "));"
'Do it
CurrentDb.Execute strSQL, dbFailOnError
Me.Requery
'get a recordset with all the detail from the original order
strSQL = "select * from tblorderdetails " _
& "where tblOrderDetails.OrderID = " &
Forms!frmOrdersMain!txtOldOrderID
'now copy the old details using the new OrderID
Set rsobj = CurrentDb.OpenRecordset("tblOrderDetails") 'target table
Set rstran = CurrentDb.OpenRecordset(strSQL) 'transaction
table
With rstran
.MoveFirst
While Not rstran.EOF
rsobj.AddNew
rsobj!OrderID = [OrderID]
rsobj!ProductID = !ProductID
rsobj!CategoryID = !CategoryID
rsobj!UnitPrice = !UnitPrice
rsobj!Quantity = !Quantity
rsobj!Discount = !Discount
rsobj.Update
.MoveNext
Wend
End With
rstran.Close
rsobj.Close
Set rstran = Nothing
Set rsobj = Nothing
'overwrite the obviously superceded fields...
Me.Requery
Me.ShippedDate = Date + 2
Me.CustPOnum = vbNull
Me.OrderDate = Date
cmdOK.Enabled = True
End Sub
Kim said:
I've looked at this issue a thousand different ways and just cannot come
up
with the solution. I've always gotten great advice here so I'm hoping you
guys will give this a go.
I have three standard tables tblCust, tblOrder, tblOrdDetail. When my
user
enters the main form, he would like a pop up box asking him whether he
wants
to copy the customer's last order to a current order. If so, the fields
should populate with the last order (order and order details) and he
should
be able to make changes. If not, he would like a blank screen to enter a
new
order.
I'm sure there's an easy solution that I'm missing but after researching
for
a week and trying every kind of query and coding I can think of, I'm out
of
ideas. Any brilliant suggestions?
Thank you for your time and consideration
Kim