G
Gordon
I have 2 tables: tblOrders and tblOrdersDetail.
tblOrders has the following fields: OrderID, OrderDate
tbltOrdersDetail has these fields: OrdersDetailID, OrderID, ProductID, Quantit
What I am trying to do is, when an order is returned, I can click a button o
my frmOrder to automatically enter a new record in tblOrder, then ne
records in tblOrdersDetail, whose ProductIDs are the same as the origina
order, with each Quantity is a negative value of the original Quantity
I tried with the following code to complete the 2nd part of the work
Private Sub Return_Click(
Dim db As DAO.Database, rs As DAO.Recordse
Dim RtnOrderID As String, RtnProductID As String, strCriteria As Strin
Dim intCriteria As Integer, RtnQuantity As Intege
Set db = CurrentD
Set rs = db.OpenRecordset("tblOrdersDetail", dbOpenDynaset
strCriteria = Forms![frmOrders]![SelectOrder
With r
.FindFirst "OrderID = '" & strCriteria & "'
Do While Not .NoMatc
intCriteria = DLookup("OrdersDetailID", "tblOrdersDetail", "OrderID = '" & strCriteria & "'"
RtnOrderID = strCriteria & "R
RtnProductID = DLookup("ProductID", "tblOrdersDetail", "OrdersDetailID =" & intCriteria
RtnQuantiry = -1 * DLookup("Quantity", "tblOrdersDetail", "OrdersDetailID =" & intCriteria
.AddNe
!OrderID = RtnOrderI
!ProductID = RtnProductI
!Quantity = RtnQuantit
.Updat
.FindNext "OrderID = '" & strCriteria & "'
Loo
End Wit
End Su
When there is only one product under an order, the code works fine. Bu
when there are more than two products under an order, the code can
add as many rows as the original order to the tblOrdersDetail table. Bu
each row is the same: copy the first ProductID, enter a negative value o
the first Quantity. Can anyone tell what is wrong in my code? Thanks
tblOrders has the following fields: OrderID, OrderDate
tbltOrdersDetail has these fields: OrdersDetailID, OrderID, ProductID, Quantit
What I am trying to do is, when an order is returned, I can click a button o
my frmOrder to automatically enter a new record in tblOrder, then ne
records in tblOrdersDetail, whose ProductIDs are the same as the origina
order, with each Quantity is a negative value of the original Quantity
I tried with the following code to complete the 2nd part of the work
Private Sub Return_Click(
Dim db As DAO.Database, rs As DAO.Recordse
Dim RtnOrderID As String, RtnProductID As String, strCriteria As Strin
Dim intCriteria As Integer, RtnQuantity As Intege
Set db = CurrentD
Set rs = db.OpenRecordset("tblOrdersDetail", dbOpenDynaset
strCriteria = Forms![frmOrders]![SelectOrder
With r
.FindFirst "OrderID = '" & strCriteria & "'
Do While Not .NoMatc
intCriteria = DLookup("OrdersDetailID", "tblOrdersDetail", "OrderID = '" & strCriteria & "'"
RtnOrderID = strCriteria & "R
RtnProductID = DLookup("ProductID", "tblOrdersDetail", "OrdersDetailID =" & intCriteria
RtnQuantiry = -1 * DLookup("Quantity", "tblOrdersDetail", "OrdersDetailID =" & intCriteria
.AddNe
!OrderID = RtnOrderI
!ProductID = RtnProductI
!Quantity = RtnQuantit
.Updat
.FindNext "OrderID = '" & strCriteria & "'
Loo
End Wit
End Su
When there is only one product under an order, the code works fine. Bu
when there are more than two products under an order, the code can
add as many rows as the original order to the tblOrdersDetail table. Bu
each row is the same: copy the first ProductID, enter a negative value o
the first Quantity. Can anyone tell what is wrong in my code? Thanks