Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-12-2019, 07:19 AM   #1
Cark
Newly Registered User
 
Join Date: Dec 2016
Posts: 153
Thanks: 61
Thanked 1 Time in 1 Post
Cark is on a distinguished road
Preventing users from removing attachments from the Attachment Control in a Form

I have an Attachment Control on a Form and would like to modify the way in which it works so that a user cannot accidentally click "Remove" when they are meaning to click "Add...". Is there a way I can do one or any of the following to introduce a bit more security to keeping the Attachments protected? Like in most situations there will come a time where someone has accidentally attached the incorrect file and I will want to remove it, so could this be controlled in such a way where a password would need to be entered or certain buttons would need to be clicked (e.g to unlock the entire record from being editable?) / a pop-up could appear?

Any examples that people could attach would be really helpful as I am new to the Attachments Control, but can envisage a lot of issues with keeping the attachments linked as users will always find a way of breaking things, so I would like to protect it with as much code as possible.
Attached Images
File Type: png Capture.PNG (5.6 KB, 17 views)

Cark is offline   Reply With Quote
Old 06-12-2019, 07:28 AM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 7,246
Thanks: 63
Thanked 1,678 Times in 1,633 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Preventing users from removing attachments from the Attachment Control in a Form

Hi. I don't have an example but the only thing I could think of is to use/create your own custom control where you can design what it can or cannot do.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 06-12-2019, 10:11 AM   #3
Mark_
Longboard on the internet
 
Join Date: Sep 2017
Location: Not the middle of no where, but I can see the road to it from my house.
Posts: 2,112
Thanks: 20
Thanked 405 Times in 396 Posts
Mark_ will become famous soon enough Mark_ will become famous soon enough
Re: Preventing users from removing attachments from the Attachment Control in a Form

Hi Cark,

Rather than keeping the attachments in your database I strongly suggest keeping a path to them. This avoids issues with database bloat and issues with proper display/edit of attached files.

In your case you would have a child table that holds the paths to attachments (more than one) and can disallow deletions from this table. More to the point, you can also have a file dialog set up that lets your users save attachments to pre-defined folders that you create and then the path to the attachment is saved. You would just need to prevent end users from going in to that folder itself outside of your program.

If this approach will work, I can talk you through several approaches on how to set this up to see if any will work for your specific needs.

Mark_ is offline   Reply With Quote
Old 06-13-2019, 01:32 AM   #4
Cark
Newly Registered User
 
Join Date: Dec 2016
Posts: 153
Thanks: 61
Thanked 1 Time in 1 Post
Cark is on a distinguished road
Re: Preventing users from removing attachments from the Attachment Control in a Form

Hi Mark_,

I had been reading up on attachments and came across the idea of database bloat as you mentioned. Although I don't envisage this particular database reaching the 2gb file size limit, I appreciate it is important to learn new techniques and also to implement best practices so you don't getting bitten in the backside later on down the line because you didn't "envisage" things.

I'm interested in learning all your suggestions. Will these work in subforms?
Cark is offline   Reply With Quote
Old 06-13-2019, 08:00 AM   #5
Mark_
Longboard on the internet
 
Join Date: Sep 2017
Location: Not the middle of no where, but I can see the road to it from my house.
Posts: 2,112
Thanks: 20
Thanked 405 Times in 396 Posts
Mark_ will become famous soon enough Mark_ will become famous soon enough
Re: Preventing users from removing attachments from the Attachment Control in a Form

For all approaches you would have a child record that holds the path to the attachment.

Simple approach; User copies attachment to a location then uses a file dialog to find the attachment. Pro: Very easy to set up. Con: Easiest way for the users to mess up and put the attachment in the wrong place.

Reasonable approach; Users uses the file dialog to identify the attachment. Your program then copies the attachment to the proper location and saves the path. Pro: Highly unlikely an end user will put a file in the wrong place. Con: More difficult to set up and requires some type of configuration for where attachments are.

Secure approach; User uses the file file dialog to identify the attachment. File is copied to a location where another process copies it to a save location that users cannot delete from and give the attachment a new name. Pro: Means your end users can't accidentally overwrite or delete attachments. Con: Will take a bit of work to set up and will need a process running on the server to handle copy / rename.

From what I gather your users are at least somewhat familiar with how directories work. As such, using the first approach may work best for you. If you find that users are doing silly things you may need to do more to prevent them from deleting files.

The two biggest advantages this has are 1) You can edit the attachments fairly easily and 2) you can do backups to only get the updated attachments instead of redundant copies of everything.

let us know if you need help with getting any of this to work.
Mark_ is offline   Reply With Quote
Old 06-18-2019, 12:20 AM   #6
Cark
Newly Registered User
 
Join Date: Dec 2016
Posts: 153
Thanks: 61
Thanked 1 Time in 1 Post
Cark is on a distinguished road
Re: Preventing users from removing attachments from the Attachment Control in a Form

All sounds like really good stuff and I appreciate you breaking down the pros and cons of different approaches. Having multiple approaches to pick from is really useful to me so that I can pick based on my individual needs.

Do you by any chance have any examples of this working in practice that you are able to share? I would like to trial the different approaches myself before trying to create one myself from scratch.
Cark is offline   Reply With Quote
Old 06-18-2019, 07:57 AM   #7
Mark_
Longboard on the internet
 
Join Date: Sep 2017
Location: Not the middle of no where, but I can see the road to it from my house.
Posts: 2,112
Thanks: 20
Thanked 405 Times in 396 Posts
Mark_ will become famous soon enough Mark_ will become famous soon enough
Re: Preventing users from removing attachments from the Attachment Control in a Form

Here is code I use to find an image and fill in the path for a record:

Code:
Private Sub Btn_FindImage_Click()
Dim asFile As String
Dim afDialog As Office.FileDialog

   Set afDialog = Application.FileDialog(msoFileDialogFilePicker)
   With afDialog
       .Title = "Select Image"
       .InitialView = msoFileDialogViewLargeIcons
       If .Show = True Then
          asFile = Trim(afDialog.SelectedItems(1))
          Me.ImageFile = asFile
          Me.Img.Picture = asFile
       Else
           MsgBox "File selection cancelled by user"
       End If
   End With
End Sub
in the code I'm not limiting the file type because some people like scanning an image into a .PDF file for some strange reason. This code is called from a button. In your case you'd want to cancel saving if they don't actually choose an image file for one of your child records.

I don't have examples of the more elaborate methods, but both rely on copying the file. You would use the basic code above to identify the file and use something like CopyFile to copy from your users selected name to a directory and name you generate.


Mark_ is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
File Attachments: Possible to limit attachment size? ulieq Macros 5 10-25-2019 10:06 AM
[SOLVED] how to send attachments using path's instead of attachment field sspreyer Modules & VBA 2 04-08-2014 01:59 PM
Sending Attachment fields to Email as Attachments wrweaver Modules & VBA 7 09-18-2013 07:26 PM
export attachments from attachment type field dcultraro VB.NET 0 02-22-2010 07:50 AM
preventing users from seeing the previous records in a particular form? jun90 Forms 2 01-10-2010 09:59 AM




All times are GMT -8. The time now is 12:45 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World