473,503 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB code to delete a file from Access DB.

40 New Member
Hello,

I have a problem with a block of code I'm trying to use that enables me to delete a file from not only the database, but the referenced folder in which the file is located.
It will delete the file from the database (removes the picture from the form), but doesn't permantely remove the file. Here's what I have:

Private Sub Form_AfterDelConfirm(Status As Integer)
Dim DeleteFilename As String
If Status = acDeleteOK Then
If Len(DeleteFilename) > 0 Then
Dim DeleteImgPath As String
DeleteImgPath = GetImageFolder & "Images\" & DeleteFilename

' Delete the image file if it exists
If Dir(DeleteImgPath) <> vbNullString Then Kill DeleteImgPath
End If
End If

DeleteFilename = ""
End Sub


This is a subForm amongst other code that I have. Also, I get a complier error - mismatch type for the ampersand on the 6th line of code.....
Any insight anyone could give would be most appreciated.
Thanks in advance.
Oct 12 '06 #1
1 2261
willakawill
1,646 Top Contributor
Hello,

I have a problem with a block of code I'm trying to use that enables me to delete a file from not only the database, but the referenced folder in which the file is located.
It will delete the file from the database (removes the picture from the form), but doesn't permantely remove the file. Here's what I have:

Private Sub Form_AfterDelConfirm(Status As Integer)
Dim DeleteFilename As String
If Status = acDeleteOK Then
If Len(DeleteFilename) > 0 Then
Dim DeleteImgPath As String
DeleteImgPath = GetImageFolder & "Images\" & DeleteFilename

' Delete the image file if it exists
If Dir(DeleteImgPath) <> vbNullString Then Kill DeleteImgPath
End If
End If

DeleteFilename = ""
End Sub


This is a subForm amongst other code that I have. Also, I get a complier error - mismatch type for the ampersand on the 6th line of code.....
Any insight anyone could give would be most appreciated.
Thanks in advance.
line 8 does indeed contain an error
DeleteImgPath = GetImageFolder & "Images\" & DeleteFilename

When you are returning a value from a function you need to include the parentheses:

DeleteImgPath = GetImageFolder() & "Images\" & DeleteFilename
Oct 12 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1352
by: ziggs | last post by:
I have an Access 97 DB called employees.mdb within a NT security type folder. Other users have write privileges to this document to make updates. This Access DB is only used for an ASP called...
1
3999
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
3
25021
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown....
18
18297
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
3
3770
by: guoqi zheng | last post by:
Dear sir, There is an import tool on my web application, user can upload Ms Access file, the file is saved at a temp folder on the server. After the import is finished, for security reason, I...
5
38940
by: wo20051223 | last post by:
Deleting some files with C# fails with "Access to the path 'X' is denied". I have files copied from a CD that I burned (and not locked by a process) and a text file that I created in Windows...
15
8505
by: sunchunkui | last post by:
Dear all, I have an Access mdb file which I updated every other week on a server. There are multiple users to access it. Usually when if somebody is using it, I can see .ldb file under that...
2
2398
by: jjbnfo | last post by:
Hi all, I'm trying to edit VBA code in my mdb file for a form. Basically, I want to delete and comment out some lines of code. (I'm quite good at VBA, so I don't need help there). I'm...
3
2053
by: Steph | last post by:
hello, i ve a probleme when deleting a directory and when i want create file immediatly after. 1) Directory.Delete(myPath, true); 2) TextWriter sw = new StreamWriter(myPath +"test.aspx"); i...
0
2977
by: JFKJr | last post by:
I have an excel file, which has columns C and D grouped together, I am trying to delete blank columns and rows from the excel file, ungroup the columns and import the file to MS Access using Access...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7258
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7313
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.