I have a master table 'JB_Jobs' which is linked to several child tables. I have simplified my code to delete the parent record while there are no child records. I keep getting an error condition.
CODE:
Private Sub cmdDeleteRecords_Click()
Dim cnt As Integer
Dim delBid As String
On Error GoTo deleteRecordsError
Set db = CurrentDb()
Set JBrec = db.OpenRecordset("JB_Jobs", dbOpenDynaset)
'delete this job
delstrSql = "JB_Deletesw = true and JB_JoborBid = false"
JBrec.FindFirst delstrSql
Do While Not JBrec.NoMatch
delBid = JBrec(0)
MsgBox " Ready to delete bid " & strQuote & delBid & strQuote
'MsgBox "Found matching Job record"
JBrec.Delete
MsgBox "Deleted " & strQuote & delBid & strQuote & " Bid record"
JBrec.FindFirst delstrSql
If JBrec.NoMatch Then
MsgBox "findnextfirst Bid is no match"
Requery
End If
Loop
If JBrec.NoMatch Then
MsgBox "There are no Bid records to delete"
Call Form_Close
End If
Exit Sub
deleteRecordsError:
MsgBox "deleteRecordsError"
End Sub
Questions:
1 - Now it seems as if it can't find the first matching record (there is only one record that meets criteria)?
2 - can I use JBrec.Delete after JBrec.FindFirst?
3 - How can I capture the error number?
Thanks for any help
CODE:
Private Sub cmdDeleteRecords_Click()
Dim cnt As Integer
Dim delBid As String
On Error GoTo deleteRecordsError
Set db = CurrentDb()
Set JBrec = db.OpenRecordset("JB_Jobs", dbOpenDynaset)
'delete this job
delstrSql = "JB_Deletesw = true and JB_JoborBid = false"
JBrec.FindFirst delstrSql
Do While Not JBrec.NoMatch
delBid = JBrec(0)
MsgBox " Ready to delete bid " & strQuote & delBid & strQuote
'MsgBox "Found matching Job record"
JBrec.Delete
MsgBox "Deleted " & strQuote & delBid & strQuote & " Bid record"
JBrec.FindFirst delstrSql
If JBrec.NoMatch Then
MsgBox "findnextfirst Bid is no match"
Requery
End If
Loop
If JBrec.NoMatch Then
MsgBox "There are no Bid records to delete"
Call Form_Close
End If
Exit Sub
deleteRecordsError:
MsgBox "deleteRecordsError"
End Sub
Questions:
1 - Now it seems as if it can't find the first matching record (there is only one record that meets criteria)?
2 - can I use JBrec.Delete after JBrec.FindFirst?
3 - How can I capture the error number?
Thanks for any help