Shell function

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

I'm using Access xp.

I posted earlier, and am having many troubles with the shell function. All
I'm trying to do is launch the "C:\I386\Scanpst.exe" application to check for
corrupted pst files from an Access module (Actually, I'd like to eventually
do this via a vb script, but I though I'd start here as I am getting
nowhere).

With each and every version of the shell function I find and copy into a
blank module I get the following error:

Compile error:
Expected variable or procedure, not project


What is this? I've tried numerous versions of code available on the
internet for shelling out to other apps. None of them work. All i want to
do is open this scanpst application, control some of the menu items through
code, and then let it run, then shut it down.


Here is what i found at Dev Ashish's site (should I even be using this?):


Option Compare Database

'************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiShellExecute 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

'***App Window Constants***
Public Const WIN_NORMAL = 1 'Open Normal
Public Const WIN_MAX = 3 'Open Maximized
Public Const WIN_MIN = 2 'Open Minimized

'***Error Codes***
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

'***************Usage Examples***********************
'Open a folder: ?fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app: ?fHandleFile("mailto:[email protected]",WIN_NORMAL)
'Open URL: ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
' ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
' ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
'****************************************************

Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)

If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
& stFile, WIN_NORMAL)
lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
Case ERROR_FILE_NOT_FOUND:
stRet = "Error: File not found. Couldn't Execute!"
Case ERROR_PATH_NOT_FOUND:
stRet = "Error: Path not found. Couldn't Execute!"
Case ERROR_BAD_FORMAT:
stRet = "Error: Bad File Format. Couldn't Execute!"
Case Else:
End Select
End If
fHandleFile = lRet & _
IIf(stRet = "", vbNullString, ", " & stRet)
End Function
'************ Code End **********


Then, I launch it like this:

Sub LaunchShell()
Call fHandleFile("C:\i386\SCANPST.EXE", WIN_NORMAL)
End Sub


Am I on the right path here? Thanks for the help.
 
Alex:

Thanks for the reply. I get the same error message. It appears at the
following line of code...

varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
& stFile, WIN_NORMAL)

Any thoughts?

Thanks.
 
Hello Doug...

stFile is the variable that is getting the name of the file and path sent to
it. If you look further down in the thread you'll see the following:

Call fHandleFile("C:\i386\SCANPST.EXE", WIN_NORMAL)

This sends the path name to fHandleFile function.

Scanpst is run by simply double-clicking the executable. It pops up a
dialog box asking for a pst file to run diagnostics. That's it.

Thanks.
 
Just a follow-up...

All I'd like to accomplish at this point is to successfully shell out to
this application. I'm not even sure that the code below is what I should be
using. If there is a simpler way of achieving this, please inform.

Thank you.
 
I think all you need is

varTaskID = Shell("C:\I386\Scanpst.exe", WIN_NORMAL)

or even just

Shell "C:\I386\Scanpst.exe", WIN_NORMAL

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Craig said:
Just a follow-up...

All I'd like to accomplish at this point is to successfully shell out to
this application. I'm not even sure that the code below is what I should
be
using. If there is a simpler way of achieving this, please inform.

Thank you.
 
OK...this brings me back to my original issue.

I can't get by the error message:

Compile error:
Expected variable or procedure, not project

Am I missing a library reference or something? When I compile it does not
like the word "Shell"
 
Do you have something else (like a module) called "Shell" anywhere in your
database? That would cause this type of error. If so, either rename the
module or change "Shell" to "VBA.Shell", and that should fix the problem.


Rob
 
Back
Top