Martin Reid
mwp.reid at qub.ac.uk
Sat Jan 6 09:19:52 CST 2007
Getting this worked out. If I add an attachment to a record and the attachment already exists then I get an error. Which is OK. What I was wondering is there an easy way to tell the user there is a file of this name already there BUT let the user overwrite it?
I suppose I could pop up a message on the error ask the user if they would like to delete the current file and then add the "new" one. Just thought of that typing this.
Does that sound reasonable or would there be better way to handle this?
Is there a way to check the version of a file as well. So if the file being attached was later than the one already there we could pop up a message and let the user add it? This bit I would need a code example for.
The code for the attach is below. If anyone is using a better method PLEASE pass it on. The attachment is a child recordset of the parent. In this case the Tasks recordset is the parent recordset with attachments being the child recordset.
Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
Dim rstTasks As Recordset2
Dim rstAttach As Recordset2
Dim fld As Field2
Set rstTasks = Me.Recordset
Set rstAttach = rstTasks.Fields("Attachments").Value
Set fld = rstAttach.Fields("FileData")
rstTasks.Edit
rstAttach.AddNew
fld.LoadFromFile "C:\logo3.gif"
rstAttach.Update
rstTasks.Update
Exit_cmdAdd_Click:
On Error Resume Next
If Not (fld Is Nothing) Then fld.Close: Set fld = Nothing
If Not (rstAttach Is Nothing) Then rstAttach.Close: Set rstAttach = Nothing
If Not (rstTasks Is Nothing) Then rstTasks.Close: Set rstTasks = Nothing
Exit Sub
Err_cmdAdd_Click:
MsgBox Err.Description, , "Error in Sub Form_Tasks.cmdAdd_Click"
Resume Exit_cmdAdd_Click
Resume 0 '.FOR TROUBLESHOOTING
End Sub
Martin
Martin WP Reid
Training and Assessment Unit
Riddle Hall
Belfast
tel: 02890 974477