When record Deleted, also delete file connected to a link

D

DeDBlanK

Thank you in advanced for the help.
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.
Thank again for the help,
DeDBlanK
 
J

John W. Vinson

Thank you in advanced for the help.
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.
Thank again for the help,
DeDBlanK

What are the "files" and what kind of link? Are you talking about a filename
stored in a text field in a table record, or the Access backend database
containing the linked table, or what? How are you deleting the record - in
code, on a form, or what? More details please!
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
D

DeDBlanK

What are the "files" and what kind of link? Are you talking about a filename
stored in a text field in a table record, or the Access backend database
containing the linked table, or what? How are you deleting the record - in
code, on a form, or what? More details please!
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com

I am using a front end and a mysql backend.
Files can be anything from a pdf, jpeg, gif, xls, doc, etc.
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.
I will try and check this later today as my day is over.
Thanks for the help.
 
D

DeDBlanK

I am using a front end and a mysql backend.
Files can be anything from a pdf, jpeg, gif, xls, doc, etc.
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.
I will try and check this later today as my day is over.
Thanks for the help.- Hide quoted text -

- Show quoted text -

Mr. Vinson, seems as if you are the only on that views these groups
regularly. =D
 
D

DeDBlanK

Anyone?- Hide quoted text -

- Show quoted text -

Reposting hoping to get an answer:
Thank you in advanced for the help.
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.
 
M

Marshall Barton

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.
 
D

DeDBlanK

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 -

Thanks Marsh. Sorry the example was confusing. I reposted this over
on microsoft forum and got a solution.
http://social.msdn.microsoft.com/Forums/en-US/accessdev/thread/8e32c703-f635-440a-88cb-4eb886a062b7
Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top