Attaching Documents

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to provide my users the ability to 'attach' a document from Word
or Excel to a record.

Is this possible?
 
In your table, add a field of type Hyperlink.

The user can then insert a link to the Word or Excel document.

More info:
Introduction to Hyperlink fields
at:
http://allenbrowne.com/casu-09.html

If you wanted to put a little command button on your form beside this text
box, just use this code in the button's Click event procedure:

Me.[NameOfYourHyperlinkFieldHere].SetFocus
RunCommand acCmdInsertHyperlink
 
I'm not really clear on what you mean by 'attach'.

If you use a field of type OLE Object instead of Hyperlink in your table,
you can insert a copy of the file into the database. That's like attaching
in the sense that if you move, delete, or alter the original file in the
disk, the inserted copy is still the original file. The disadvantage of this
approach is that the Access database bloats and becomes impossibly large
very quickly. So, while it is possible, it is not really practical.
 
Alan,
I found a reply you had on 3/8/06 regarding attaching (linking) files to an
access database. This work great. My next question - is there a way to
include a "Browse" function so the person filling out the form doesn't have
to type the whole address, they can just "Browse" and click on the file they
want to attach?

Thanks

David

Allen Browne said:
In your table, add a field of type Hyperlink.

The user can then insert a link to the Word or Excel document.

More info:
Introduction to Hyperlink fields
at:
http://allenbrowne.com/casu-09.html

If you wanted to put a little command button on your form beside this text
box, just use this code in the button's Click event procedure:

Me.[NameOfYourHyperlinkFieldHere].SetFocus
RunCommand acCmdInsertHyperlink

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

PosseJohn said:
I would like to provide my users the ability to 'attach' a document from
Word
or Excel to a record.

Is this possible?
 
Sure can. This link has the code:
http://www.mvps.org/access/api/api0001.htm

If you have not used an API call before, it may look a bit scary, but it is
easy to use. Just copy everything betwen the "Code Start" and "Code End"
lines into a standard module. Then run TestIt().

There are alternatives that look easier, but none of them are reliable and
versatile as this.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

DDrowe said:
Alan,
I found a reply you had on 3/8/06 regarding attaching (linking) files to
an
access database. This work great. My next question - is there a way to
include a "Browse" function so the person filling out the form doesn't
have
to type the whole address, they can just "Browse" and click on the file
they
want to attach?

Thanks

David

Allen Browne said:
In your table, add a field of type Hyperlink.

The user can then insert a link to the Word or Excel document.

More info:
Introduction to Hyperlink fields
at:
http://allenbrowne.com/casu-09.html

If you wanted to put a little command button on your form beside this
text
box, just use this code in the button's Click event procedure:

Me.[NameOfYourHyperlinkFieldHere].SetFocus
RunCommand acCmdInsertHyperlink
 
Allen,
Some days are better than others - then happens to be an other.
I have copied the code to a module and named it TestIt. How do I run
TestIt()?

Thanks again.

David

Allen Browne said:
Sure can. This link has the code:
http://www.mvps.org/access/api/api0001.htm

If you have not used an API call before, it may look a bit scary, but it is
easy to use. Just copy everything betwen the "Code Start" and "Code End"
lines into a standard module. Then run TestIt().

There are alternatives that look easier, but none of them are reliable and
versatile as this.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

DDrowe said:
Alan,
I found a reply you had on 3/8/06 regarding attaching (linking) files to
an
access database. This work great. My next question - is there a way to
include a "Browse" function so the person filling out the form doesn't
have
to type the whole address, they can just "Browse" and click on the file
they
want to attach?

Thanks

David

Allen Browne said:
In your table, add a field of type Hyperlink.

The user can then insert a link to the Word or Excel document.

More info:
Introduction to Hyperlink fields
at:
http://allenbrowne.com/casu-09.html

If you wanted to put a little command button on your form beside this
text
box, just use this code in the button's Click event procedure:

Me.[NameOfYourHyperlinkFieldHere].SetFocus
RunCommand acCmdInsertHyperlink
 
Name the module something like Module1.
It cannot have the same name as the function.

After that, test that Access understands it correctly, by choosing Compile
on the Debug window (in the code window.)

Then open the Immediate window (press Ctrl+G), and enter:
Call TestIt

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

DDrowe said:
Allen,
Some days are better than others - then happens to be an other.
I have copied the code to a module and named it TestIt. How do I run
TestIt()?

Thanks again.

David

Allen Browne said:
Sure can. This link has the code:
http://www.mvps.org/access/api/api0001.htm

If you have not used an API call before, it may look a bit scary, but it
is
easy to use. Just copy everything betwen the "Code Start" and "Code End"
lines into a standard module. Then run TestIt().

There are alternatives that look easier, but none of them are reliable
and
versatile as this.

DDrowe said:
Alan,
I found a reply you had on 3/8/06 regarding attaching (linking) files
to
an
access database. This work great. My next question - is there a way
to
include a "Browse" function so the person filling out the form doesn't
have
to type the whole address, they can just "Browse" and click on the file
they
want to attach?

Thanks

David

:

In your table, add a field of type Hyperlink.

The user can then insert a link to the Word or Excel document.

More info:
Introduction to Hyperlink fields
at:
http://allenbrowne.com/casu-09.html

If you wanted to put a little command button on your form beside this
text
box, just use this code in the button's Click event procedure:

Me.[NameOfYourHyperlinkFieldHere].SetFocus
RunCommand acCmdInsertHyperlink
 
OK - I renamed it, verified that Access understood it and then type TestIT in
the Immediate Window. Everything looked great except when I chose a file it
put 400 below TestIt in the Intermediate Window. I have a hyperlink field on
the form and I hit Ctrl+G from there and it did the same thing - asked if the
file I selected was the right one then put a 400 in the Immediate Window.

I know I'm missing something easy here - I just cant see it.

Thanks

David

Allen Browne said:
Name the module something like Module1.
It cannot have the same name as the function.

After that, test that Access understands it correctly, by choosing Compile
on the Debug window (in the code window.)

Then open the Immediate window (press Ctrl+G), and enter:
Call TestIt

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

DDrowe said:
Allen,
Some days are better than others - then happens to be an other.
I have copied the code to a module and named it TestIt. How do I run
TestIt()?

Thanks again.

David

Allen Browne said:
Sure can. This link has the code:
http://www.mvps.org/access/api/api0001.htm

If you have not used an API call before, it may look a bit scary, but it
is
easy to use. Just copy everything betwen the "Code Start" and "Code End"
lines into a standard module. Then run TestIt().

There are alternatives that look easier, but none of them are reliable
and
versatile as this.

Alan,
I found a reply you had on 3/8/06 regarding attaching (linking) files
to
an
access database. This work great. My next question - is there a way
to
include a "Browse" function so the person filling out the form doesn't
have
to type the whole address, they can just "Browse" and click on the file
they
want to attach?

Thanks

David

:

In your table, add a field of type Hyperlink.

The user can then insert a link to the Word or Excel document.

More info:
Introduction to Hyperlink fields
at:
http://allenbrowne.com/casu-09.html

If you wanted to put a little command button on your form beside this
text
box, just use this code in the button's Click event procedure:

Me.[NameOfYourHyperlinkFieldHere].SetFocus
RunCommand acCmdInsertHyperlink
 
Okay, it is working.

You can now ask for an MDB file by trying this in the Immediate window:
Call GetOpenFile()

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

DDrowe said:
OK - I renamed it, verified that Access understood it and then type TestIT
in
the Immediate Window. Everything looked great except when I chose a file
it
put 400 below TestIt in the Intermediate Window. I have a hyperlink field
on
the form and I hit Ctrl+G from there and it did the same thing - asked if
the
file I selected was the right one then put a 400 in the Immediate Window.

I know I'm missing something easy here - I just cant see it.

Thanks

David

Allen Browne said:
Name the module something like Module1.
It cannot have the same name as the function.

After that, test that Access understands it correctly, by choosing
Compile
on the Debug window (in the code window.)

Then open the Immediate window (press Ctrl+G), and enter:
Call TestIt

DDrowe said:
Allen,
Some days are better than others - then happens to be an other.
I have copied the code to a module and named it TestIt. How do I run
TestIt()?

Thanks again.

David

:

Sure can. This link has the code:
http://www.mvps.org/access/api/api0001.htm

If you have not used an API call before, it may look a bit scary, but
it
is
easy to use. Just copy everything betwen the "Code Start" and "Code
End"
lines into a standard module. Then run TestIt().

There are alternatives that look easier, but none of them are reliable
and
versatile as this.

Alan,
I found a reply you had on 3/8/06 regarding attaching (linking)
files
to
an
access database. This work great. My next question - is there a
way
to
include a "Browse" function so the person filling out the form
doesn't
have
to type the whole address, they can just "Browse" and click on the
file
they
want to attach?

Thanks

David

:

In your table, add a field of type Hyperlink.

The user can then insert a link to the Word or Excel document.

More info:
Introduction to Hyperlink fields
at:
http://allenbrowne.com/casu-09.html

If you wanted to put a little command button on your form beside
this
text
box, just use this code in the button's Click event procedure:

Me.[NameOfYourHyperlinkFieldHere].SetFocus
RunCommand acCmdInsertHyperlink
 
I type that in, it opens and Open window asking for an MDB file. I select a
file and the open window goes away and I am back to the Immediate window one
line below the "Call GetOpenFile()" line with nothing else writen.

Allen Browne said:
Okay, it is working.

You can now ask for an MDB file by trying this in the Immediate window:
Call GetOpenFile()

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

DDrowe said:
OK - I renamed it, verified that Access understood it and then type TestIT
in
the Immediate Window. Everything looked great except when I chose a file
it
put 400 below TestIt in the Intermediate Window. I have a hyperlink field
on
the form and I hit Ctrl+G from there and it did the same thing - asked if
the
file I selected was the right one then put a 400 in the Immediate Window.

I know I'm missing something easy here - I just cant see it.

Thanks

David

Allen Browne said:
Name the module something like Module1.
It cannot have the same name as the function.

After that, test that Access understands it correctly, by choosing
Compile
on the Debug window (in the code window.)

Then open the Immediate window (press Ctrl+G), and enter:
Call TestIt

Allen,
Some days are better than others - then happens to be an other.
I have copied the code to a module and named it TestIt. How do I run
TestIt()?

Thanks again.

David

:

Sure can. This link has the code:
http://www.mvps.org/access/api/api0001.htm

If you have not used an API call before, it may look a bit scary, but
it
is
easy to use. Just copy everything betwen the "Code Start" and "Code
End"
lines into a standard module. Then run TestIt().

There are alternatives that look easier, but none of them are reliable
and
versatile as this.

Alan,
I found a reply you had on 3/8/06 regarding attaching (linking)
files
to
an
access database. This work great. My next question - is there a
way
to
include a "Browse" function so the person filling out the form
doesn't
have
to type the whole address, they can just "Browse" and click on the
file
they
want to attach?

Thanks

David

:

In your table, add a field of type Hyperlink.

The user can then insert a link to the Word or Excel document.

More info:
Introduction to Hyperlink fields
at:
http://allenbrowne.com/casu-09.html

If you wanted to put a little command button on your form beside
this
text
box, just use this code in the button's Click event procedure:

Me.[NameOfYourHyperlinkFieldHere].SetFocus
RunCommand acCmdInsertHyperlink
 
If you select an Access database and click the Open button, you should see
the fully qualified file name listed on the next line if the Immediate
window.

To assign the file name to TextBox0 in your form, you would write code like
this:
Me.TextBox0 = GetOpenFile()
 
But I want to attach Word Documents to an existing database mostly, possible
an Excel spreadsheet or maybe a picture.

Will this work for those items? I have it where the person filling in the
form can manually type in any link.

Thanks

David
 
Change the line:
strFilter = ahtAddFilterItem(strFilter, _
"Access (*.mdb)", "*.MDB;*.MDA")
to:
strFilter = ahtAddFilterItem(strFilter, _
"All files (*.*)", "*.*")
or to:
strFilter = ahtAddFilterItem(strFilter, _
"Word documents (*.doc)", "*.DOC")
or whatever you want.
 
Ok - that was easy. But, when I run the GetOpenFile() it asks for the file,
I select the file then it goes back to the immediate window and drops to the
next line without the corresponding file name. I know its doing something,
but as far as I can tell its not putting it somewhere accessible.

Thanks for all the help this morning.

David
 
You should see the file name printed on the next line in the Immediate
window.

Not sure what else to suggest if you are not seeing that. Perhaps you could
set a break point (F9), and single-step through the code to see what it is
doing and what results it is getting.
 
I dont know. It appears to work but does not print the file name on the next
line. I'll play with it some more today and see what I can come up with.

Thanks again for all your help.

David
 
Back
Top