Code to delete record and linked file

  • Thread starter Thread starter Todd
  • Start date Start date
T

Todd

I have code on a continuous form that lists all documents related to a
particular client. Each row of the form has a field that contains a
hyperlink to the associated file [Link]. I created a button that would
delete the record and the corresponding file. The code gets an error
messgae when it gets to the 2nd "DoCmd" line. It asks me if I'm sure that I
want to delete the record. I click "yes" and then I get the message... "No
current record" and the file is not deleted because the code has stopped.
Any idea why I'm getting this message? Am I missing something simple? Here
is the code...

Private Sub delfile_Click()
On Error GoTo Err_Delete_File_and_Link_Click
Dim strFile As String
Dim length As Integer

'DELETE FILE LINKED
'Remove # signs from link
length = Len([Link])
strFile = Left([Link], length - 1)
strFile = Right(strFile, length - 2)

'Delete record
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

'Test and delete file
Debug.Print strFile
Kill (strFile)

Exit_Delete_File_and_Link_Click:
Exit Sub

Err_Delete_File_and_Link_Click:
MsgBox Err.description
Resume Exit_Delete_File_and_Link_Click
End Sub
 
If this occurs in Access 2002 (Office XP) with Service Pack 3 applied, the
error message is a known Access bug.

You can work around the problem by trapping the error number and resuming
instead of exiting.
 
Thanks for the help! That was it!

Allen Browne said:
If this occurs in Access 2002 (Office XP) with Service Pack 3 applied, the
error message is a known Access bug.

You can work around the problem by trapping the error number and resuming
instead of exiting.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Todd said:
I have code on a continuous form that lists all documents related to a
particular client. Each row of the form has a field that contains a
hyperlink to the associated file [Link]. I created a button that would
delete the record and the corresponding file. The code gets an error
messgae when it gets to the 2nd "DoCmd" line. It asks me if I'm sure that
I want to delete the record. I click "yes" and then I get the message...
"No current record" and the file is not deleted because the code has
stopped. Any idea why I'm getting this message? Am I missing something
simple? Here is the code...

Private Sub delfile_Click()
On Error GoTo Err_Delete_File_and_Link_Click
Dim strFile As String
Dim length As Integer

'DELETE FILE LINKED
'Remove # signs from link
length = Len([Link])
strFile = Left([Link], length - 1)
strFile = Right(strFile, length - 2)

'Delete record
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

'Test and delete file
Debug.Print strFile
Kill (strFile)

Exit_Delete_File_and_Link_Click:
Exit Sub

Err_Delete_File_and_Link_Click:
MsgBox Err.description
Resume Exit_Delete_File_and_Link_Click
End Sub
 
Back
Top