Re: Using a function to print
- From: "Douglas J. Steele" <NOSPAM_djsteele@xxxxxxxxxxxxxxxxx>
- Date: Wed, 21 May 2008 11:05:04 -0400
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
.
- Follow-Ups:
- Re: Using a function to print
- From: JIM
- Re: Using a function to print
- From: JIM
- Re: Using a function to print
- References:
- Using a function to print
- From: JIM
- Re: Using a function to print
- From: Douglas J. Steele
- Re: Using a function to print
- From: JIM
- Using a function to print
- Prev by Date: Re: Using a function to print
- Next by Date: Re: How to copy/paste text from a form to email
- Previous by thread: Re: Using a function to print
- Next by thread: Re: Using a function to print
- Index(es):
Relevant Pages
|
Loading