UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Managing Attachments Programmatically., Access 2010    
 
   
HairyBob
post Aug 19 2015, 09:52 AM
Post#1



Posts: 875
Joined: 26-March 08
From: London


I recently started looking at the Attachment field / associated Attachment control and noticed that there's no way of disabling any of the options available through the 'Manage Attachments' window, so I thought I'd have a go at this programmatically. I was thinking (for example) that someone might ask me to allow users to edit and add attachments without being able to remove them, or maybe be able to open attachments without being able to edit them etc.

I posted the following which theDBGuy responded to and which helped me a lot...

http://www.UtterAccess.com/forum/index.php...2030655&hl=

Then I posted this, which both Jack Leach and theDBGuy responded to (thanks to both!):

http://www.UtterAccess.com/forum/index.php...2030789&hl=

Please see the attched file for what I finally came up with... Using frmManageAttachments, you can add, delete and open/edit attachments without being able to 'Save As' or 'Save All'.

If anyone has suggestions for improvements they will be much appreciated.

NB: I tried posting this in the Code Archive as theDBGuy suggested; however, the post wouldn't save.

Hairy.
Attached File(s)
Attached File  Manage_Attachments.zip ( 72.74K )Number of downloads: 16
 
Go to the top of the page
 
theDBguy
post Aug 19 2015, 10:25 AM
Post#2


Access Wiki and Forums Moderator
Posts: 71,225
Joined: 19-June 07
From: SunnySandyEggo


Hi Hairy. Thanks for sharing. I'll go check why you can't post it in the Code Archive (where I think it really belongs).
Go to the top of the page
 
theDBguy
post Aug 19 2015, 10:33 AM
Post#3


Access Wiki and Forums Moderator
Posts: 71,225
Joined: 19-June 07
From: SunnySandyEggo


Hi Hairy. I gave it a quick spin, but when I attached an Excel spreadsheet and then opened it to make some changes, I got the following error:
Attached File  error.png ( 6.93K )Number of downloads: 0

It's a file I created, and it's on my Desktop.

Edit: Wait... This might not be an issue with your code. I tried to use the regular Manage Attachments window and got the following error instead:
Attached File  unable.png ( 13.53K )Number of downloads: 0

It must have something to do with my permissions to the Temp folder at work.

Edit #2: Unfortunately, when I tried to modify the code to use my Desktop folder as the Temp folder, I still got the first error. frown.gif

Edit #3: I'm sorry, I am getting some inconsistent results. Now, when I try using the built-in Manage Attachments window, I am not getting the second error anymore. I don't know what's happening... Perhaps somebody else should give it a try and let us know how it goes. Other than the problems I am getting, I think this approach has some potentials. Just my 2 cents...
Go to the top of the page
 
Larry Larsen
post Aug 19 2015, 11:17 AM
Post#4


UA Editor + Utterly Certified
Posts: 24,110
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi
No problems here.. all seems to work well.

If I was to add any thing to the process would be some details based around capturing both date & times for either adding or editing the attachments.

Appart from that all works ok.. notworthy.gif
thumbup.gif
Go to the top of the page
 
theDBguy
post Aug 19 2015, 11:22 AM
Post#5


Access Wiki and Forums Moderator
Posts: 71,225
Joined: 19-June 07
From: SunnySandyEggo


Thanks, Larry! I will definitely try it again at home tonight.

Hairy, I looked into the Code Archive issue. There is no problem. Your submission is in there, and it just needs to go through the approval process now. Cheers!
Go to the top of the page
 
HairyBob
post Aug 19 2015, 01:40 PM
Post#6



Posts: 875
Joined: 26-March 08
From: London


Hi DBGuy,

I've just tried at home and I occasionally get 'Permission Denied' as well.

Maybe this shouldn't go into the Archive just yet.

Thanks to both you and Larry for giving it a try.

Hairy.
Go to the top of the page
 
theDBguy
post Aug 19 2015, 01:58 PM
Post#7


Access Wiki and Forums Moderator
Posts: 71,225
Joined: 19-June 07
From: SunnySandyEggo


Hi Hairy. If you manage to find the cause of the problem, I can update the code archive submission or just delete it. Let me know...
Go to the top of the page
 
Larry Larsen
post Aug 19 2015, 02:01 PM
Post#8


UA Editor + Utterly Certified
Posts: 24,110
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi Hairy

I was using my PC at home and didn't have any errors, it set dir in my user directory..??
thumbup.gif
Go to the top of the page
 
HairyBob
post Aug 20 2015, 02:24 AM
Post#9



Posts: 875
Joined: 26-March 08
From: London


Hi Larry & theDBGuy,

This morning, I took a copy of the file and commented out all error traps. I then attached new files and opened/edited existing files.

Unfortunately, I haven't been able to reproduce the 'Permissions Denied' error sad.gif .

Larry: I don't know why it set Dir in your user directory; there's nowhere in the code where I change directory. When opening an attachment, the file is saved to the folder specified by the "Temp" environment variable. On my work PC this is "C:\Documents and Settings\<user>\Local Settings\Temp".

I'm going to try and find out where the error is occurring when I get home tonight... I will post again to let you know if I have any success (or that the post should be removed from the Archive if I don't).

One difference between work and home is that I have Access 2010 at work and Access 2007 at home; however, I don't see why there would be a problem when running with 2007 instead of 2010.

Again, thanks to both.

Hairy.
Go to the top of the page
 
theDBguy
post Aug 20 2015, 07:57 PM
Post#10


Access Wiki and Forums Moderator
Posts: 71,225
Joined: 19-June 07
From: SunnySandyEggo


Hi Hairy. I finally got a chance to try this at home. Unfortunately, I still get the permission denied error. frown.gif
Go to the top of the page
 
HairyBob
post Aug 21 2015, 03:05 AM
Post#11



Posts: 875
Joined: 26-March 08
From: London


Hi theDBGuy and Larry,

On my PC at home, I found that the 'Permissions Denied' error was occurring when deleting the temporary file - it would appear that although the window had been closed, the file had not yet been released. I've therefore added code to ignore any 'Permissions Denied' error and re-try every 100ms in a loop, testing for when the file has been deleted and if so, exiting the loop (I've indluded a timeout of 10 seconds in case the file cannot be deleted within that time) - see attached file.

I've also noticed that if all attachments are deleted via the form, then the form closed and re-opened, there is still a record with no attachment. I tried changing the code in Form_Open() of sfrmManageAttachments from simply moving to the new record row to the following:

CODE
Private Sub Form_Open(Cancel As Integer)

    If Me.Recordset.RecordCount > 0 Then
        If IsNull(Me.Recordset.Fields("Files.FileName")) Then
            CurrentDb.Execute "DELETE * " & Mid(Me.RecordSource, InStr(Me.RecordSource, "FROM")), dbFailOnError
            Me.Requery
        End If
    Else
        DoCmd.RunCommand acCmdRecordsGoToNew
    End If

End Sub


So that if there is a single record with no attachment when the subform opens, it is deleted; however, this also deleted the row in the table (not just the row in the attachment multi-valued field). Therefore, I don't think that approach is a good idea considering that the user may want to delete all attachments from a row in the table leaving the table row in place.

In addition to the above, the code doesn't seem to register when a window is closed in some cases; for example, if I attach an SQL script file, double-click to open it with SQL Management Studio, edit it, then close the window without closing Management Studio, the window is not recognised as having been closed; it only registers when Management Studio is closed.

Considering all this, I think that the whole thing is too flakey and shouldn't be in the Code Archive; DBGuy - could you please have it removed.

Yet again many thanks to Larry and the theDBGuy for your help in this experiment thanks.gif .

Hairy.
Attached File(s)
Attached File  Manage_Attachments.zip ( 237.22K )Number of downloads: 5
 
Go to the top of the page
 
theDBguy
post Aug 21 2015, 04:03 PM
Post#12


Access Wiki and Forums Moderator
Posts: 71,225
Joined: 19-June 07
From: SunnySandyEggo


Hi Hairy. Sorry to hear that. I still applaud you for all the hard work you put into this. However, this is a very good example of how much "extra" work one can get into when trying to "replicate" or customize a feature that's already built-in. I'll remove your submission from the Code Archive. Good luck!
Go to the top of the page
 
HairyBob
post Aug 22 2015, 08:16 AM
Post#13



Posts: 875
Joined: 26-March 08
From: London


I hear you DBGuy !

Still... I did enjoy the exercise and it's probably not the last rabbit hole I'll go down!

Thanks again thumbup.gif

Hairy.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    14th December 2017 - 01:03 AM