Win7-Runtime Problem with ShellExecute

craigachan

Registered User.
Local time
Today, 07:34
Joined
Nov 9, 2007
Messages
285
I'm wondering if someone can give me insight to a problem that I have. I have 3 db called AOMSChart.accdb, AOMSSurgery.accdb and AOMSLetters.accdb. I've run the following code from AOMSChart.accdb on Win XP and Win Vista systems without problems in both full Access 2007 and Runtime versions.

Code:
Public Function Launch(FN As String, PTFile As String)
' FN = File Name
' PTFILE = Path to File
On error goto Err_Launch

Launch = ShellExecute(0, "open", FN, "", PTFile, 1)

LaunchExit:
Exit Function

Err_Launch:
Msgbox Err.Number & ": " & Err.Description
Resume LaunchExit

End Function

I will use the above code to launch various other Access DBs such as:

Code:
Private Sub cmdSurg_Click()
'this launches AOMSSurgery.accdb
'FN = File Name
' PTFILE = Path to File
Dim FN As String
Dim PTFile As String

FN = DLookup("AOMSSurgery", "CHANLinkPaths")   '  
PTFile = ""

Call Launch(FN, PTFile)		'Public

End Sub

The above code works fine on all windows systems including Win 7. However the following code works in Ac2007 but not in runtime on any of my Win 7 workstations. I can launch the AOMSLetters.accdb from Explore and from the cmd, but not form this code.

Code:
Private Sub cmdLtr_Click()
'this launches AOMSLetters.accdb
'FN = File Name
' PTFILE = Path to File

Dim FN As String
Dim PTFile As String

FN = DLookup("AOMSLtr", "CHANLinkPaths")   
PTFile = ""

Call Launch(FN, PTFile)		'Public

End Sub

I'm baffled and would appreciate any input to my problem. Both the FE dbs are keep in the mydocuments folder on the workstations. I'm not even sure its even related to Win7 at all. When I click the cmdLtr button nothing happens and no errors.
 
Have you got this in you declarations section

Code:
Private Declare Function ShellExecute Lib "shell32.dll" _
   Alias "ShellExecuteA" _
   (ByVal hWnd As Long, ByVal lpszOp As String, _
    ByVal lpszFile As String, ByVal lpszParams As String, _
    ByVal LpszDir As String, ByVal FsShowCmd As Long) _
    As Long
Private Declare Function GetDesktopWindow Lib "User32" () As Long

Const SW_SHOWNORMAL = 1

Then this in the launch function

Code:
    nDT = GetDesktopWindow()
    nApp = ShellExecute(nDT, "Open", strFile, "", "C:\", SW_SHOWNORMAL)

Where strFile is the file to open
 
And there's an alternative way which requires NO USE of Shell Execute.
Code:
Dim objAcc As Access.Application
 
Set objAcc = CreateObject("Access.Application")
 
objAcc.OpenCurrentDatabase(YourVariableToDBWithPathAndExtenstionHere)
 
objAcc.UserControl = True
 
Set objAcc = Nothing

And there you have how you can open an Access database without Shell Execute. The part with .UserControl breaks the link to the variable and you can destroy the variable without affecting the now open database.
 
Last edited:
Thanks for your reply, Bob. Can you see anything wrong with my code? I'm curious.

I'm going to use your code. Thanks very much.
 
Thanks for your reply, Bob. Can you see anything wrong with my code? I'm curious.
Nothing that I can tell. It is likely something that Windows 7 has a problem with because of executing something. There may be a way around it using elevated permissions but that is out of my experience.
 
Thanks Drake, just saw your post. Yes, I have the declare, and it's pretty close to yours. I'm wondering if there is something different with Win7 that causes this problem.
 
Hi Bob,

Redid my code to your and it works great with Acc2007 full version, but does not work with runtime. I get: 429: ActiveX Can't Create Object. I'm not sure if i'm missing a reference or not. I tried MS DAO 3.6 Object Library as suggested by someone but it conflicts with what I already have. Any suggestions?

Craig
 

Users who are viewing this thread

Back
Top Bottom