Re: Using a function to print



When you saved the code, you didn't happen to name the module ExecuteFile
did you? If so, rename the module. Modules cannot have the same name as subs
or functions.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"JIM" <JIM@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5CCDF4A2-3D53-47A4-A04B-52CB4C1975A9@xxxxxxxxxxxxxxxx
Thanks so much, Doug. I checked Require Variable Declar. and added option
explicit to module. Also reiterated the variables in subroutine. Now it
says Compile error Expected Function or variable and highlights
ExecuteFile.
In help it says:
The syntax of your statement indicates a variable or function call. This
error has the following cause and solution:
The name isn't that of a known variable or Function procedure.
Check the spelling of the name. Make sure that any variable or function
with
that name is visible in the portion of the program from which you are
referencing it. For example, if a function is defined as Private or a
variable isn't defined as Public, it's only visible within its own module.
(or)
You are trying to inappropriately assign a value to a procedure name. For
example if MySub is a Sub procedure, the following code generates this
error:
MySub = 237 ' Causes Expected Function or variable error

Although you can use assignment syntax with a Property Let procedure or
with
a Function that returns an object or a Variant containing an object, you
can't use assignment syntax with a Sub, Property Get, or Property Set
procedure.

I've checked everything in help message. What am I missing?
Thanks, JIM

"Douglas J. Steele" wrote:

Try declaring sFileName:

Private Sub Option62_Click()
Dim sFileName As String
Dim vReturn As Variant

sFileName = Me.txtMapLoc
vReturn = ExecuteFile(sFileName, "Print")

End Sub

The fact that your code raised that error leads me to believe that you
haven't told Access to require declaration of all variables. You should.
To
do this, go into the VB Editor and select Tools | Options from the menu
bar.
Look at the Editor tab: one of the options there should be "Require
Variable
Declaration". What this means is that all future modules you create will
have Option Explicit as the first or second line of the file. You should
go
back to all of your existing modules and add that line. While it may seem
like a lot of work declaring all your variables, in the long run it'll
save
you huge amounts of time as you try to figure out why your code isn't
doing
what it should when you've made a typo on a variable name!


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"JIM" <JIM@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B99C948D-2FFD-4A83-9FF1-BE1CAFAAC8CE@xxxxxxxxxxxxxxxx
I'm trying to make a function work found on-line. My module looks like
this:
Option Compare Database

Public Const SW_Hide = 0
Public Const SW_Minimize = 6
Public Const SW_Restore = 9
Public Const SW_Show = 5
Public Const SW_ShowMazimized = 3
Public Const SW_ShowMinimized = 2
Public Const SW_ShowMinnoActive = 7
Public Const SW_Showna = 8
Public Const SW_ShownoActivate = 4
Public Const SW_ShowNormal = 1

Public Declare Function ShellExecute Lib "Shell32.dll" Alias
"ShellExecuteA"
(ByVal hWnd As Long, ByVal IpOperation As String, ByVal IpParameters As
String, ByVal IpDirectory As String, ByVal nShowCmd As Long) As Long

Public Sub ExecuteFile(sFileName As String, sAction As String)
'sAction
can
be either "Open" or "Print"
Dim vReturn As Long

If ShellExecute(Access.hWndAccessApp, sAction, sFileName,
vbNullString,
SW_ShowNormal) < 33 Then
MsgBox "File not found"
End If
End Sub

Then in my click event on a form the code looks like this:

Private Sub Option62_Click()
sFileName = Me.txtMapLoc
vReturn = ExecuteFile(sFileName, "Print")
End Sub

I get "Compile error: Byref argument type mismatch" And after
thinking -
it's probably saying this is not a file name, which it is not. The
control
txtMapLoc has in it the location of the file (ie F:Plans\Xcel.doc) not
the
file name. How can I implement this function using the location?
Thanks,
JIM





.



Relevant Pages

  • Re: Using a function to print
    ... can't use assignment syntax with a Sub, Property Get, or Property Set ... Dim sFileName As String ... haven't told Access to require declaration of all variables. ... Public Const SW_Minimize = 6 ...
    (microsoft.public.access.modulesdaovba)
  • Re: Using a function to print
    ... It doesn't like sFileName. ... can't use assignment syntax with a Sub, Property Get, or Property Set ... Dim sFileName As String ... Public Const SW_Minimize = 6 ...
    (microsoft.public.access.modulesdaovba)
  • Re: Using a function to print
    ... Private Sub Option62_Click ... Dim sFileName As String ... Public Const SW_Minimize = 6 ...
    (microsoft.public.access.modulesdaovba)
  • Re: Using a function to print
    ... It doesn't like sFileName. ... can't use assignment syntax with a Sub, Property Get, or Property Set ... Dim sFileName As String ... Public Const SW_Minimize = 6 ...
    (microsoft.public.access.modulesdaovba)
  • Re: Return Control to Userform
    ... Public Const MOUSEEVENTF_LEFTDOWN = &H2 ... Sub LeftClick() ... I'm not sure if the Putfocus would have worked or not as I alt/tabbed ... ByVal lpWindowName As String) As Long ...
    (microsoft.public.excel.programming)

Loading