DeDBlanK said:
Not sure what event to use for the code to delete the files connected
to a link in a record that is being deleted. Any suggestions?
I also need to know if anyone has any ideas on how to loop through
link in my records and find files in a directory that don't match the
links I have in my records. In other words files that don't match
links. Just not sure how to approach this, which I am sure is not
difficult for some.
I am using access as a front end to my mysql backend.
Files can be anything from a pdf, jpeg, gif, xls, doc, etc. your
basic documents.
The link is text stored as a string (i.e. //svus1/comp_db/db/files/
text.txt).
So, I want to compare the links in the tblLinks against the files in
the stated directory ( //svus1/comp_db/db/files/).
tblLinks directory
-link1 file1
-link2 file2
-link3 file3
file4
-link5 file5
In the above case, I would want to delete `file4`. I could run an
unmatch query against if they both were tables, and then kill the
files.
Deleting records is done by selecting the record on the form and
pressing the delete key on the keyboard, then confirming the delete.
Your example is confusing. You said the link is a full path
to a file, but then you show a column called directory with
a list of file names.
If the link column contains a string that is a folder path
such as:
//svus1/comp_db/db/files/
and you have a file name column that is a tring with only
the file name, then you could use the Dir function to see if
the file exists in the folder. VBA code something like:
Dim db As Database
Set db = CurrentDb()
If Dir(link & filename) = "" Then
' file not in folder, delete record
db.Execute "DELETE * FROM tablelinks " _
WHERE link = '" link _
& "' And filename = '" filename & "' "
End If
Set db = Nothing
It will take a little more than that depending on how you
are accessing the records in the table. You might want to
use a recordset if you use a command button to do them all
at once or maybe you want to use a form to view each record
in the table and check/delete each record by itself.
--
Marsh
MVP [MS Access]- Hide quoted text -
- Show quoted text -