adding an attachment and view a file in a form

  • Thread starter Thread starter chris1980
  • Start date Start date
C

chris1980

hi. i was wondering if it is possible for a user to attach a file in a
form for each specific record and to have some kind of button next to
the attachment to view it also in the same record. i have been banging
my head trying to find a way to work it out but cannot. any help would
be really great.
Thanks
 
Chris,

You can add a field to your table, Hyperlink data type. In this field
you can enter the path/file of the "attachment", for example...
C:\YourFolder\YourFile.pdf

Depending in the file type, I believe it is more reliable if your entry
is preceded by the file: protocol identifier, for example...
file:C:\YourFolder\YourFile.pdf

Of course, this relies on the filename extension being recognised by
Windows.
 
Steve said:
Chris,

You can add a field to your table, Hyperlink data type. In this field
you can enter the path/file of the "attachment", for example...
C:\YourFolder\YourFile.pdf

Depending in the file type, I believe it is more reliable if your entry
is preceded by the file: protocol identifier, for example...
file:C:\YourFolder\YourFile.pdf

Of course, this relies on the filename extension being recognised by
Windows.
 
Thanks alot steve. i will try to implement this tomorrow and i will for
sure let you know. this makes alot of sense though. thanks once again
 
hey steve. i tried your solution did not work for me. here is what i am
doing with my database. i have a form and a button by the name of
(AddaFile) for each record. what i really want to do is if a user
clicks on AddaFile button in the form he should be able to attach a
file so then other people who have access to that database can see
what the whole issue was about. i want the user to add a file in the
form by just clicking on that button and each and every record and have
that addafile button. once they have added the file i was wondering if
he/she can also view that attachment. if you can help me out that will
be great.
 
Chris,

What is the AddAFile button supposed to do? How is the database
supposed to know which file to add? My suggestion was focussed more on
the second part of your question, in other words the viewing of the
document. If the file's path/name is entered in the field, then simply
click on it and the attached file should open.
 
Thanks for replying Steve. when a user clicks on AddaFile button it
will let the user choose a file from his Computer hard drive like the
file name is ISSUE2. when he clicks on that addafile button i want him
to add an attachment file to that record so that for our superiors when
they access the database they can see the file directly in the record
related to that that Issue rather than emailing them personally. there
is always a different issue file for each record. and for viewing i
think once i am able to attach a file for that specific record the user
will be automatically able to view that file whatever format the file
is. i am still on computer so i will be answering your questions.
Thanks for your help
 
Chris,

Ok, just to clarify, you can't literally attach a file to the record.
What you are doing is entering the path/name of the file into a field in
the table.

So, there are two separate processes.

One is the process of entering the file's path/name into the database.
The simplest method, of course, is to just type it in (assuming you know
it!) If you want the user to have access to a file explorer/selection
dialog, you will need to use some API code. There is some good
information on this at http://www.mvps.org/access/api/api0001.htm

The other is, once the file's path/name is entered into the database, to
open that file for the current record. If the file's path/name is
entered into a field with a hyperlink data type, you can just click on
the textbox on the form, and the file should open. An alternative
approach, if you want to use a command button to open the file, is to
use code like this...
Application.FollowHyperlink Me.NameOfFieldWithFileName
 
i have already tried that api code. i created a module and copied the
code in a standard module but it gives me an error on StrFilter for
some reason i am still trying to debug that problem. and i was reading
these forums MSaccess i have seen a guy posting that he already have
created a button to attach a file in a form but his question was how to
submit that form through email or something like that. the second
process you told me i believe that all the users who are entering the
data in the form need to enter a valid path of the file in the table
and then add that Onclick procedure you just give me to view it. IS
this the only efficient way to do it? Anyways thanks for your help and
i will try to do this thing rite now i have been wrokin on it 2 weeks
nights and days searching cause i think everything is possible :).
Appreciate that i will keep you updated.
Thanks
 
hey. i tried to make a field by the name of attachment in the table and
then created a text box in the form so then the hyperlink i have in my
table will automatically appear in the form but when i click on the
hyperlink in the form it says that (hyperlinks can be harmful only use
trusted sources, etc) if you click yes the document opens if no then it
does not open the document. can i get rid of that message?
 
And yes Somehow This works the table thing but not an efficient way but
its better than nothing :). Thanks for your help steve. still curious
about that msg which is displayed once you click on the link.
 
Sorry, Chris, I have not encountered this. What type of files are they?
 
Chris,

Just to summarise/clarify...

The path/file name ultimately needs to be entered into the table in any
case. No matter what method you use to access the file, its path and
name need to be recorded in the table. Normally this will be done via
the form interface. So in this regard, really the choices are either to
enter the path/file name by typing it into a textbox, or to enter the
path/file name by selecting it from the Windows File common dialog,
which is what the API code is all about. But the end result is still
the same - the path and name of the file is recorded in a field in a table.

And then, there is the question of accessing the file from within the
database application. Again, two choices. Either the field you use to
store the path/file name is a hyperlink data type, and you open the file
by clicking directly on the form control. Or you use some other event,
such as clicking a command button, in which case you need to use code.
The FollowHyperlink method I mentioned is one approach - there are others.

So (apart form the "unsafe hyperlink" warning message you are getting),
is there any problem with any of this? I am not sure I understand what
you mean about efficiency.
 
I got it steve thanks for all your help and replies i really appreciate
that. Followhyperlink works fine came to know i need to have a # sign
in the beginning and at the end. Thanks alot steve. i am still a newbie
and i am in love now working with access. i try to take the hardest
projetcs which no one can do in my company and do alot of research
learn more so then one day i can be an MVP also :). take care
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top