Using Access forms to open other documents

H

hermanko

Hi,

I am working on a low-level document control manager using Access,
which will store different file information for files that need to be
controlled (i.e. with revisions and read-only access).

Some of the file types include Word, Excel and .PDF files....

I've created a form (single) that displays each record's information
(File ID, Name, Latest Version, etc), and I would like to add a cmd
button that will associate each record to the ACTUAL location on my
network (or hard drive). So when the user clicks this cmd button called
"Open File" it will actually open the .pdf file, or .doc, etc....

Can Access do this? (I've only been using access for a few months) It
just seems like when i add the button on the form (in the detail
section) it's more like a "generic" button and i can have links to the
actual file depending on which record needs to be opened.

Thanks for any help!
Herman
 
S

strive4peace

Hello Herman,

try this:

application.followhyperlink "c:\path\filename.ext"

"I would like to add a cmd button that will associate each
record to the ACTUAL location on my network (or hard drive)"

does this mean that you are storing a filename without its path?

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
F

fredg

Hi,

I am working on a low-level document control manager using Access,
which will store different file information for files that need to be
controlled (i.e. with revisions and read-only access).

Some of the file types include Word, Excel and .PDF files....

I've created a form (single) that displays each record's information
(File ID, Name, Latest Version, etc), and I would like to add a cmd
button that will associate each record to the ACTUAL location on my
network (or hard drive). So when the user clicks this cmd button called
"Open File" it will actually open the .pdf file, or .doc, etc....

Can Access do this? (I've only been using access for a few months) It
just seems like when i add the button on the form (in the detail
section) it's more like a "generic" button and i can have links to the
actual file depending on which record needs to be opened.

Thanks for any help!
Herman

You can use a regular text field that stores the path to and the name
of the file you want to open, i.e. "c:\FolderName\MyDoc.doc".
Then code the command button click event:

Application.FollowHyperlink [ControlName]
 
S

strive4peace

Hi Arvin,

Is there an advantage to using Shell over FollowHyperlink?

Thanks

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
A

Arvin Meyer [MVP]

Shell is a VB/VBA function, but ShellExecute is an api function, built into
the core of Windows. So if the filetype is registered, it will automatically
open it without needing to figure out which program to do so. If it isn't
registered, it will automatically bring up the standard Windows Open With
Dialog. Hyperlinks won't do that.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
S

strive4peace

Thanks, Arvin.

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
H

hermanko

Hey guys,

Thanks for the great input!

With this function shellexecute, do I put it in a Module? Also, my
other confusion is that say i have 10 records that i can navigate
through on my Form....I currently have a cmd button called cmd_opendoc
that i want to have the user click on to open the application and file
that relates to that particular record.

i.e. record 1 is a Word doc called Doc1.doc.... but how do I get it so
that each command button is different? It seems that if i change the
properties for one record, it is the same for all records. Another way
to explain it is, when i move to the next record view....i see the same
cmd_opendoc button........

Thanks
Herman
 
H

hermanko

I was able to get the shellexecute api to work, using the fHandleFile
function. On clicking the cmd button on my form i was able to open the
file perfectly.

However, my database is a collection of different files for each record
(document control database), so each record will have a different file
associated with it. So when i navigate to the next record, and click on
the command button, it opens the first file. the problem is that it's
hardcoded in (the function parameters)....I thought about reference the
textbox that contains the file name for each record, but realize that
the text box is the SAME for all records....what can I do to solve
this?

Herman

Appreciate your help!
 
S

strive4peace

Hi Herman,

send the textbox control name as a parameter -- it will only
have ONE value -- that of the record you are currently on

you may want to test to make sure it is filled before you
SHELL out

'~~~~~~~~~~~~~~~~~~`
if isnull(me.controlname) then
msgbox "You do not have a file specified" _
,,"No Current Record"
else
'... statements
end if
'~~~~~~~~~~~~~~~~~~`

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
S

strive4peace

you're welcome, Herman :) happy to help

btw, its ARvin...

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
H

hermanko

Oops! My mistake Arvin :p I didn't mean to mispell your name.

I do have a followup question to add now...

Is there a way to use that api
(http://www.mvps.org/access/api/api0018.htm) and when I open the
document from within Access, have it force the file to be read-only? As
my database is to control the latest revisions of documents, I would
not want someone to open a doc and inadvertently save it after his/her
own changes. I realize that one can just set the read-only property
when u right-click on the file itself, but i was curious if there was a
way to do that in Access?

Furthermore, would it be possible to grab the file properties of any
windows registered file (i.e. .xls, .doc, etc) and update that in my
table? For example, is there a way to grab the "last modified"
information from an excel file's properties and read that into a table
in Access? Right now I am just manually typing in that info, so there
won't be any automation when the actual file is modified. That would be
a great bonus feature!

Thanks,
Herman
 
S

strive4peace

Hi Herman

before you shell out, make file read-only:
SetAttr "c:\path\Filename.ext", vbReadOnly

you can use GetAttr to get attributes


Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
A

Arvin Meyer [MVP]

No harm.

If you want to change the file attributes, Crystal's code is the trick. If
you want to protect the document itself from within an automation instance
(in this case using an Early bound reference) try something like this code
stub:

Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")

WordTemplate = Application.CurrentProject.Path & "\Letter.dot"

With objWord
.Visible = True
.Documents.Add (WordTemplate)

' If document is protected, Unprotect it.
If .ActiveDocument.ProtectionType <> wdNoProtection Then
.ActiveDocument.Unprotect Password:=""
End If

' Do something here, then

' ReProtect the document.
If .ActiveDocument.ProtectionType = wdNoProtection Then
.ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
NoReset:=True
End If
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
S

strive4peace

Hi Herman,

to get the modification date of a file, here is some code
you can adapt:

'~~~~~~~~~~~~~~
'NEEDS REFERENCE to Microsoft Scripting Runtime
'Tools, References from a VBA module

Dim mfile As Scripting.File

Dim fso As Scripting.FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")

For Each mfile In fso.GetFolder("c:\path").Files

msgbox "Modified: " & mfile.DateLastModified _
, , mfile.Name

Next mfile
'~~~~~~~~~~~~~~

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 

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

Similar Threads

Browse button for access form 1
open PDF from form 2
A little help 3
Open folder view in explorer by button 3
Access Access variable string for export 0
Access Access Reports 0
Open files from Access Form 5
Open Specific Record 1

Top