Arvin Meyer: question about shellexecute api!

H

hermanko

Hi Arvin,

I have used your ShellExecute api function
(http://www.mvps.org/access/api/api0018.htm) for my document control
database. It works fine in that it will open any windows-registered
file from within my database forms.

However, is there a way to modify or add a line of code within your
code to force the file being opened to be Read-Only? I don't really
understand your code as i'm a newbie. Is it possible to do what I'm
requesting in an easy way? Basically my reason for asking is that I
don't want a user to open a document and then save any changes as that
would defeats the purpose of having a database for controlled docs.

Thanks Arvin for any help!
Herman
 
D

Douglas J Steele

I believe that the only way to accomplish that would be to change the
default Open behaviour for that file extension. In other words, if you're
willing to have any file you opened by double-clicking open read-only, then
you may be able to change the file association's Open action. Whether or not
it's possible, though, would depend on the specific file extension: not all
applications have a command-line switch that allow you to control whether or
not it's opening as read-only.
 
R

RoyVidar

(e-mail address removed) wrote in message
Hi Arvin,

I have used your ShellExecute api function
(http://www.mvps.org/access/api/api0018.htm) for my document control
database. It works fine in that it will open any windows-registered
file from within my database forms.

However, is there a way to modify or add a line of code within your
code to force the file being opened to be Read-Only? I don't really
understand your code as i'm a newbie. Is it possible to do what I'm
requesting in an easy way? Basically my reason for asking is that I
don't want a user to open a document and then save any changes as
that would defeats the purpose of having a database for controlled
docs.

Thanks Arvin for any help!
Herman

Depending on what kind of documents you're talking about - but for say
Word documents and Excel workbooks, I'd perhaps consider automation.

Some sample code thrown together. You'll probably need to test a bit,
if
it is applicable at all in your situation. It assumes a valid path/file
is passed

Sub OpenReadOnly(ByVal v_strFileName As String)

Dim oApp As Object
Dim oDoc As Object

Select Case LCase(Right$(v_strFileName, 3))
Case "doc"
On Error Resume Next
Set oApp = GetObject(, "word.application")
If Err.Number <> 0 Then
Err.Clear
Set oApp = CreateObject("word.application")
If Err.Number <> 0 Then
Exit Sub
End If
End If
On Error GoTo MyErr
Set oDoc = oApp.Documents.Open(v_strFileName, , True)
Case "xls"
On Error Resume Next
Set oApp = GetObject(, "excel.application")
If Err.Number <> 0 Then
Err.Clear
Set oApp = CreateObject("excel.application")
If Err.Number <> 0 Then
Exit Sub
End If
End If
On Error GoTo MyErr
Set oDoc = oApp.Workbooks.Open(v_strFileName, , True)
End Select
oApp.Visible = True

MyExit:
Set oDoc = Nothing
Set oApp = Nothing
Exit Sub
MyErr:
MsgBox Err.Description
Resume MyExit
End Sub
 

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


Top