Generally this works as expected. But when I'm dealing with multiple lines on one order it can fail if not all of them are used at once.
Not sure what you are asking????
I modified your code a little...
Code:
Private Sub Command51_Click()
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
'check to see if records on record set
If rst.BOF And rst.EOF Then
'no records - tell them
MsgBox "No records"
Else
rst.MoveLast
' MsgBox rst.RecordCount '<- for testing
rst.MoveFirst
'loop through the record set
Do Until rst.EOF
'Check Quantity
If rst!Temp_Quantity > rst!remaining_quantity Then
MsgBox "Value entered (" & rst!Temp_Quantity & ") exceeds the available quantity " & rst!remaining_quantity
'I added a space after "exceeds the available quantity" to separate the text from the number
Exit Do
End If
' If IsNull(Inv_Quantity) = True Then
' MsgBox "please input a quantity"
' Exit Do ' Exit Sub
' Else '<<-- not needed
' End If
'Check document type selected
If IsNull(DocTypeCMB) = True Then
MsgBox "please select a document type"
Exit Do
End If
'what is the data type of Me.DocTypeCMB?
' is it a number 2 or a string "2"????
Select Case Me.DocTypeCMB
Case "1"
' If Me.DocTypeCMB.Value = "1" Then
If Me.Inv_Quantity < 0 Then
MsgBox "Invoice value must be greater than 0"
Exit Do
End If
DoCmd.SetWarnings False
DoCmd.OpenQuery "append to invoice table", , acReadOnly
DoCmd.OpenQuery "Update_issue_3"
DoCmd.SetWarnings True '<<-- ALWAYS turn on warnings after you turn them off
' Else '<<-- not needed
' End If
Case "2"
' If Me.DocTypeCMB.Value = "2" Then
If Me.Inv_Quantity > 0 Then
MsgBox "Credit value must be less than 0"
Exit Do
End If
DoCmd.SetWarnings False
DoCmd.OpenQuery "append to invoice table for credit", , acReadOnly
DoCmd.SetWarnings True '<<-- ALWAYS turn on warnings after you turn them off
' Else '<<-- not needed
' End If
End Select
rst.MoveNext
Loop
End If ' If rst.BOF And rst.EOF Then
'clean up
rst.Close
Set rst = Nothing
MsgBox "Done"
End Sub
I changed "Exit Sub" to "Exit Do" because you are inside of a "DO - LOOP" . Now the code will fall through to the clean up code and end gracefully.
With the "Exit Sub" lines, the record set is not closed properly.
What is the SQL for the queries "append to invoice table for credit" and "Update_issue_3"?? They are action queries???
(
spaces in names). I would use something like "AppendInvoiceCredit" or "Append_Invoice_Credit"...
And instead of setting warnings off, I would use code like
Code:
Dim dB as DAO.Database
Set dB = Currentdb
.
.other code
.
db.Execute "append to invoice table", dbFailOnError
dB.Esecute "Update_issue_3", dbFailOnError
.
. other code
.
'clean up
Set dB = Nothing
again, just the way I code.....