This code is supposed to delete documents from local storage that are
associated with a particular record. That is, if a hyperlink to the
document exists in tblDocuments, then delete that document. But if the
document is associated with other records in the database, do not delete it.
Should be simple enough - just count the number of times the document
appears in tblDocuments and delete on the condition that it appears only
once.
lngEid = the record in question
strSql = "SELECT HyperlinkPart([Document],0) As HlkDoc FROM tblDocuments
WHERE Entity_ID = " & lngEid
Set rst = CurrentDb.OpenRecordset(strSql)
'loop through documents associated with lngEid, check each one to make sure
it's not linked to other records
Do Until rst.EOF
'this DCount statement always returns 0 - even if the hyperlink appears
multiple times in the table
intDocCt = DCount("Doc_ID", "tblDocuments", "HyperlinkPart([Document],0)
= " & rst!HlkDoc)
If intDocCt = 1 Then
strDdoc = DLookup("DocDir", "tblPrefs") & "\" & rst!HlkDoc
Set objFile = CreateObject("Scripting.FileSystemObject")
objFile.DeleteFile strDdoc
End If
rst.MoveNext
Loop
I've tried debug.print to check rst!HlkDoc - looks fine. Why does that
DCount always return 0? Are there hidden characters in HyperlinkPart? Am I
missing something, or should I maybe go about this another way?