M
Max Moor
Hi All,
So here is a little code. In plain english, I'm using ADO's Find
method to iterate through all the Categories belonging to a specific
Section. If the Category is not being used in a RegistryTable, I want
to delete it.
The problem I have is that if I delete the Category, The Find at
the end of the loop complains that the bookmark refers to a record that
is deleted, or marked for deletion. How can I manipulate the bookmark
to work around this? The code is below... Any other comments are
welcome.
- Max
Set rstCats = New ADODB.Recordset
rstCats.Open "tblFinanceCategories", CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic, adCmdTableDirect
If (Not rstCats.BOF) And (Not rstCats.EOF) Then
rstCats.Find "SecID = " & lngSecID
' Find all categories in this section
Do While (rstCats.EOF <> True)
bCatFound = False
' Get the CatID of the found cat record
lngCatID = rstCats!CatID
' Search for the category in the finance registry
vDLRet = DLookup("[CatID]", "tblRegistry", "[CatID]=" & lngCatID)
If (Not IsNull(vDLRet)) Then
' If found, can't delete the cat, or (later) the section
bDeleteSec = False
Else
' Cat not found in registry, delete it
rstCats.Delete
rstCats.Update
End If
vMark = rstCats.Bookmark
rstCats.Find "SecID = " & lngSecID, 1, adSearchForward, vBookmark
Loop
End If ' (Not rstTable.BOF) And (Not rstTable.EOF)
rstCategories.Close
So here is a little code. In plain english, I'm using ADO's Find
method to iterate through all the Categories belonging to a specific
Section. If the Category is not being used in a RegistryTable, I want
to delete it.
The problem I have is that if I delete the Category, The Find at
the end of the loop complains that the bookmark refers to a record that
is deleted, or marked for deletion. How can I manipulate the bookmark
to work around this? The code is below... Any other comments are
welcome.
- Max
Set rstCats = New ADODB.Recordset
rstCats.Open "tblFinanceCategories", CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic, adCmdTableDirect
If (Not rstCats.BOF) And (Not rstCats.EOF) Then
rstCats.Find "SecID = " & lngSecID
' Find all categories in this section
Do While (rstCats.EOF <> True)
bCatFound = False
' Get the CatID of the found cat record
lngCatID = rstCats!CatID
' Search for the category in the finance registry
vDLRet = DLookup("[CatID]", "tblRegistry", "[CatID]=" & lngCatID)
If (Not IsNull(vDLRet)) Then
' If found, can't delete the cat, or (later) the section
bDeleteSec = False
Else
' Cat not found in registry, delete it
rstCats.Delete
rstCats.Update
End If
vMark = rstCats.Bookmark
rstCats.Find "SecID = " & lngSecID, 1, adSearchForward, vBookmark
Loop
End If ' (Not rstTable.BOF) And (Not rstTable.EOF)
rstCategories.Close