By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,560 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,560 IT Pros & Developers. It's quick & easy.

Attach file to record

P: n/a
Hi

I am having trouble understanding how to attach a file or files to a
record. I want to (in form view0 allow the user to attach one or more
than one file to the associated record, and then from then have the
link displayed on the form. All the files would be displayed on the
computers harddrive (or a network folder) and not in the db itself. I
have read and reread http://www.mvps.org/access/api/api0001.htm
and understand that i need to call the save as windows dialog box. but
i dont understand the directions here. not knowing if it is code for a
seperate module or if its code i put in the form (maybe a onclick
event.)
I would really appreciate some help or suggestions on this...maybe a
sample db to look at. I am kinda new to this.
Manyh thanks
Caleb

Dec 11 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Caleb,
Everything above the '***Code Start**** goes on the *form where you
want to use the code*, like in a button's Click event..

The rest goes into its own module.

I have this code in my subform (Employees is the Mainform).
txtFilePath is just a bound textbox control in my subform.

This is an example of the FORM code...
(the module you just leave as is!)

Private Sub txtFilePath_DblClick(Cancel As Integer)
Dim strFilter As String '<---What file extension(s) are you
looking for?
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)",
"*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)

Me.txtFilePath = strInputFileName
End Sub

Then the code in your form just calls the code in the module
(ahtAddFilterItem).

If you are only ever attaching a *single* file, (Always, no exceptions,
ever.), then you can just create a field in your parent table.
Otherwise, create a child table and away you go.
Does that help?

Pieter
ca**********@yahoo.com wrote:
Hi

I am having trouble understanding how to attach a file or files to a
record. I want to (in form view0 allow the user to attach one or more
than one file to the associated record, and then from then have the
link displayed on the form. All the files would be displayed on the
computers harddrive (or a network folder) and not in the db itself. I
have read and reread http://www.mvps.org/access/api/api0001.htm
and understand that i need to call the save as windows dialog box. but
i dont understand the directions here. not knowing if it is code for a
seperate module or if its code i put in the form (maybe a onclick
event.)
I would really appreciate some help or suggestions on this...maybe a
sample db to look at. I am kinda new to this.
Manyh thanks
Caleb
Dec 11 '06 #2

P: n/a
Pieter

thanks for responding. let me see if i can suss this out.
I run the possibility of attaching more than one file. So....
Step 1. Create a new table to store the file names
AttachmentID (pk)
CompanyRepID
FileName
Step 2. Create a subform to implant on my main form. Maybe in
datasheet view?
This subform would have a boundtext box (filename) and a button with an
onlick event of
Private Sub txtFilePath_DblClick(Cancel As Integer)
Dim strFilter As String '<---What file extension(s) are you
looking for?
Dim strInputFileName As String
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)",
"*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
Me.txtFilePath = strInputFileName
End Sub
I take it this code brings up the windows save as dialog box. I have
the possibilty though of attaching not only excel files but also word
and pdf. i take it the strfilter needs to change accordingly. maybe
to this? strfilter= ahtaddfilteritem(strFilter, "All Files (*.*)",
"*.*") Is that right?
Step 3.
Take all the code under ***code start*** and create a module in the
module section and call it.....openfilename
Step 4
Insert a code for double click to open the file name when it is
displayed.

I dont know if all this is right. For instance how do i make the file
a hyperlink to be display in the subform....do i need to specify its
text name.

As you can see i am completly confused. But not as much as yesterday.
:)

thanks for your time.
Caleb



pi********@hotmail.com wrote:
Caleb,
Everything above the '***Code Start**** goes on the *form where you
want to use the code*, like in a button's Click event..

The rest goes into its own module.

I have this code in my subform (Employees is the Mainform).
txtFilePath is just a bound textbox control in my subform.

This is an example of the FORM code...
(the module you just leave as is!)

Private Sub txtFilePath_DblClick(Cancel As Integer)
Dim strFilter As String '<---What file extension(s) are you
looking for?
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)",
"*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)

Me.txtFilePath = strInputFileName
End Sub

Then the code in your form just calls the code in the module
(ahtAddFilterItem).

If you are only ever attaching a *single* file, (Always, no exceptions,
ever.), then you can just create a field in your parent table.
Otherwise, create a child table and away you go.
Does that help?

Pieter
ca**********@yahoo.com wrote:
Hi

I am having trouble understanding how to attach a file or files to a
record. I want to (in form view0 allow the user to attach one or more
than one file to the associated record, and then from then have the
link displayed on the form. All the files would be displayed on the
computers harddrive (or a network folder) and not in the db itself. I
have read and reread http://www.mvps.org/access/api/api0001.htm
and understand that i need to call the save as windows dialog box. but
i dont understand the directions here. not knowing if it is code for a
seperate module or if its code i put in the form (maybe a onclick
event.)
I would really appreciate some help or suggestions on this...maybe a
sample db to look at. I am kinda new to this.
Manyh thanks
Caleb
Dec 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.