StevenFromSouth
Programmer
I am having problems debugging this code.
If the record exist in one table and not in the other it work fine but if the the record don't exist in either table I'm getting Error 3021 No Current Record. I want to just continue without prompts If there are no Unmatched Records.
Code:
Private Sub Form_Load()
Dim delsql As String
Dim UnMatchedQry As String
Dim rst As DAO.Recordset
UnMatchedQry = "SELECT Purchases.PID" & _
" FROM Purchases LEFT JOIN PurchaseDetail ON Purchases.[PID] = PurchaseDetail.[PID] " & _
" WHERE (((PurchaseDetail.PID) Is Null));"
Set rst = CurrentDb.OpenRecordset(umq)
delsql = "DELETE FROM Purchases" & _
" WHERE PID =" & rst!PID & ""
If rst.RecordCount = 0 Then
'Cancel = True
Else
MsgBox "Cleaning up Tables....", vbInformation, "Initalizing DB"
CurrentDb.Execute (delsql )
End If
End Sub
If the record exist in one table and not in the other it work fine but if the the record don't exist in either table I'm getting Error 3021 No Current Record. I want to just continue without prompts If there are no Unmatched Records.