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
> A Button In Form To Open/delete/saveas Current Attachment, Access 2016    
 
   
orrajabi
post Jul 11 2017, 02:18 AM
Post#1



Posts: 2
Joined: 11-July 17



Dear all,
I have a table for employees which includes an attachment field for each person.
All the attachments of each person are stored in that single field.
The attachments are embedded into the database and are not linked to a folder outside the database.

Then I created the following query to list all the attachments with only a single attachment in every row:

CODE
SELECT tblPeople.personID AS Person, tblPeople.attachments.FileData AS [File Data], tblPeople.attachments.FileName AS Name, tblPeople.attachments.FileType AS Type
FROM tblPeople
WHERE (((tblPeople.attachments.FileName) Is Not Null));


Then I created a form in "single form" view that has navigation buttons to navigate through the list of all attachments one by one. Thi form displays the name and icon of a single file each time. Please note that since this form is based on the above query it lists single attachments each time and to view the three attachments of one employee you have to press NEXT three times.

I have included in this form some buttons to Open/Delete/SaveAs the current attachment and also a button to add new attachments to that field (New).

I have no idea how to make the buttons do their tasks! I thought I might need to insert some VBA code into each button event "on click" but do not know anything about VBA coding.

I will be highly grateful if you could kindly give me a helping hand.

Any help in this regard is highly appreciated in advance.

I have included an image of my table for employees, the above query, and the form I have created based on the above query.

Regards,
Omid
Attached File(s)
Attached File  Table_of_Employees.png ( 25.1K )Number of downloads: 3
Attached File  the_Query_design_view.png ( 12.85K )Number of downloads: 1
Attached File  the_Query_datasheet_view.png ( 10.69K )Number of downloads: 2
Attached File  the_form_based_on_that_query.png ( 12K )Number of downloads: 3
 
Go to the top of the page
 
DanielPineault
post Jul 11 2017, 08:51 AM
Post#2


UtterAccess VIP
Posts: 5,450
Joined: 30-June 11



Can you post a sample of your database, omitting any sensitive information, for us to review.

Yes, you'd need to create a Click event for each button and then insert the necessary code for each action.

Depending on how you have things setup, for the navigation buttons you may be able to simply use code such as:

CODE
RunCommand acCmdRecordsGoToNew 'New Record
RunCommand acCmdRecordsGoToPrevious 'Previous Record
RunCommand acCmdRecordsGoToNext 'Next Record
RunCommand acCmdRecordsGoToLast 'Last Record
RunCommand acCmdRecordsGoToFirst 'First Record


As for Saving and/or Opening the attachment, things get more dicey as you have to first save it to the hard drive to be able to do anything with it. You can find sample code to do this in the following discussion on the matter (their was an Access blog post on the matter but MS changes their links pullhair.gif that my link no longer works thumbdn.gif ): https://access-programmers.co.UK/forums/sho...ad.php?t=224112. Once you've got it save to the hd, then you can simply use Application.FollowHyperlink to open the file itself in the default program associated with the file extension.


I'd still urge you to not use the Attachment data type and switch over to simply storing the path and file name as text as demonstrated by: http://www.devhut.net/2016/10/03/adding-at...ccess-database/

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...
Go to the top of the page
 
theDBguy
post Jul 11 2017, 10:27 AM
Post#3


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


Hi,

Welcome to UtterAccess!
welcome2UA.gif

I think maybe Daniel was referring to this MS article.

Hope it helps...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
DanielPineault
post Jul 11 2017, 12:51 PM
Post#4


UtterAccess VIP
Posts: 5,450
Joined: 30-June 11



Take a look at the following sample database which should cover everything you are trying to accomplish.
Attached File(s)
Attached File  AttachmentDataType.zip ( 281.54K )Number of downloads: 7
 

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...
Go to the top of the page
 
DanielPineault
post Jul 12 2017, 11:53 AM
Post#5


UtterAccess VIP
Posts: 5,450
Joined: 30-June 11



FYI, I made a post on my site regarding this as I thought it might be helpful for others, so you can access it at

MS Access Working with Attachment Data Types

I will post future update there (I still want to add more features to completely cover the subject).

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...
Go to the top of the page
 
orrajabi
post Jul 13 2017, 01:44 AM
Post#6



Posts: 2
Joined: 11-July 17



Dear all respected members,
Thanks a lot for the time you spent on sharing all the useful info and links.
I will get back to you here in case of any further questions.
Thanks a bunch.
I found the information highly useful. smile.gif
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    12th December 2017 - 01:41 AM