error message

G

Guest

hi,

I have the following in a module saves as Module1:

Option Compare Database

Option Explicit
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal
Hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal
lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long)
As Long
Global Const SW_SHOWNORMAL = 1

Public Function StartDoc(DocName As String)
On Error GoTo StartDoc_Error
StartDoc = ShellExecute(Application.hWndAccessApp, "Open", DocName,
"", "C:\", SW_SHOWNORMAL)
Exit Function

StartDoc_Error:
MsgBox "Error: " & Err & " " & ERROR
Exit Function

End Function

Then I have a button in a form, with the following code behind it. WHen I
clicked the button to see if the code would open the "put.txt" file on my C
Drive, I got an "compile error: argument not optional" error message. How
can I fix this?

Here is te code bhing the button:
StartDoc

DocName = "put.txt"

Thanks in advance,
geebee
 
S

strive4peace

why not do something like this:

'~~~~~~~~~~~~~~

Sub OpenDoc( _
DocName As String, _
optional PathName as string)

dim mPathAndName as string

if len(nz(PathName,"")) = 0 then
'or whatever you want for a default directory
mPathAndName = "c:\"
else
mPathAndName = PathName
end if

if right(mPathAndName,1) <> "\" then
mPathAndName = mPathAndName & "\"
endif

mPathAndName = mPathAndName & DocName

Application.FollowHyperlink mPathAndName

end Sub

'~~~~~~~~~~~~~~

this assumes that your system knows what application to use to open the
specified document


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote programming and Training
strive4peace2006 at yahoo.com
*
 
G

Guest

hi,

Thanks. You are a jewel. I not have the following saved as Module1:

Sub OpenDoc( _
DocName As String, _
Optional PathName As String)

Dim mPathAndName As String

If Len(Nz(PathName, "")) = 0 Then
'or whatever you want for a default directory
mPathAndName = "c:\"
Else
mPathAndName = PathName
End If

If Right(mPathAndName, 1) <> "\" Then
mPathAndName = mPathAndName & "\"
End If

mPathAndName = mPathAndName & DocName

Application.FollowHyperlink mPathAndName

End Sub


And I have the following behind my form button:
OpenDoc
DocName = "put.txt"

I am still getting the "argument not optional" error message.

I am not sure what to do...

Thanks in advance,
geebee
 
S

strive4peace

you're welcome,

the Click event for your button would be -->
[Event Procedure]

and in your button code, put this statement -->
OpenDoc "put.txt"


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
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

Top