G
graeme34 via AccessMonster.com
Hello
Could any body please help me, I am quite new to programming and I am trying
to create an order entry system. I have a Sales order entry form with a child
order entry form for the order details. On the main form I have a cancel
order command button. In the on click property of this button I have code to
check if there have been order details entered to prevent the referential
integrity rules being broken. The problem seems to be in the Do while....loop.
It works in the sense it deletes all the related records, but it is not
coming out of the loop when the final record is deleted, I am getting the no
current record message at the Do while line, can anybody see what I am doing
wrong??
Here is the full code of the command button:
Private Sub cmdCancelOrder_Click()
Dim intMsgRes As Integer
Dim rs As DAO.Recordset
Dim rsDetail As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblSalesOrder")
Set rsDetail = CurrentDb.OpenRecordset("tblSalesOrderLine", _
dbOpenDynaset)
strTableName = "tblSalesOrderLine"
rsDetail.FindFirst "[SalesOrderNumber] = " _
& Me!txtSalesOrderNumber
If rsDetail.NoMatch = False Then
intMsgRes = MsgBox("There have been Order details added to this " _
& "Order, are you sure you want to cancel it?", _
vbYesNo, "CANCEL ORDER!")
If intMsgRes = vbNo Then Exit Sub
Do While rsDetail!SalesOrderNumber = Me!txtSalesOrderNumber _
Or Not rsDetail.EOF
rsDetail.Delete
rsDetail.MoveNext
Loop
End If
rs.MoveLast
'If statement to test if the current record has been
' saved into the table prior to deleting
If rs!SalesOrderNumber = Me!txtSalesOrderNumber Then
rs.Delete
DoCmd.Close acForm, "frmSalesOrder", acSaveYes
OpenMainMenu
rs.Close
Exit Sub
Else
DoCmd.Close acForm, "frmSalesOrder", acSaveYes
OpenMainMenu
rs.MoveLast
rs.Delete
rs.Close
End If
End Sub
Could any body please help me, I am quite new to programming and I am trying
to create an order entry system. I have a Sales order entry form with a child
order entry form for the order details. On the main form I have a cancel
order command button. In the on click property of this button I have code to
check if there have been order details entered to prevent the referential
integrity rules being broken. The problem seems to be in the Do while....loop.
It works in the sense it deletes all the related records, but it is not
coming out of the loop when the final record is deleted, I am getting the no
current record message at the Do while line, can anybody see what I am doing
wrong??
Here is the full code of the command button:
Private Sub cmdCancelOrder_Click()
Dim intMsgRes As Integer
Dim rs As DAO.Recordset
Dim rsDetail As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblSalesOrder")
Set rsDetail = CurrentDb.OpenRecordset("tblSalesOrderLine", _
dbOpenDynaset)
strTableName = "tblSalesOrderLine"
rsDetail.FindFirst "[SalesOrderNumber] = " _
& Me!txtSalesOrderNumber
If rsDetail.NoMatch = False Then
intMsgRes = MsgBox("There have been Order details added to this " _
& "Order, are you sure you want to cancel it?", _
vbYesNo, "CANCEL ORDER!")
If intMsgRes = vbNo Then Exit Sub
Do While rsDetail!SalesOrderNumber = Me!txtSalesOrderNumber _
Or Not rsDetail.EOF
rsDetail.Delete
rsDetail.MoveNext
Loop
End If
rs.MoveLast
'If statement to test if the current record has been
' saved into the table prior to deleting
If rs!SalesOrderNumber = Me!txtSalesOrderNumber Then
rs.Delete
DoCmd.Close acForm, "frmSalesOrder", acSaveYes
OpenMainMenu
rs.Close
Exit Sub
Else
DoCmd.Close acForm, "frmSalesOrder", acSaveYes
OpenMainMenu
rs.MoveLast
rs.Delete
rs.Close
End If
End Sub