Link to home
Start Free TrialLog in
Avatar of Mel Brooks
Mel Brooks

asked on

VBA ShellExecute failing when using Access Runtime 64 bit

I have the following code as part of a function I've been using in Access VBA for years with no problem to open external files based on their default program.


iRet = ShellExecute(frmName.hwnd, "open", sDocFileNamePath, "", "", nCmdShow)


This code is still working for me using 32 bit access, 64 bit access, and I'm almost positive 32 bit runtime access.  It's failing when running on a server with 64 bit Access Runtime 2016.   The error I get is " no program associated with this file type".

Which is false because I can double-click the file in Windows explorer and the jpg file opens in Paint.  also, if I run a DISM and export out file locations, it shows .jpg associated with Paint.  So why is the VBA code failing on these servers?   Any ideas.

ASKER CERTIFIED SOLUTION
Avatar of Richard Cole
Richard Cole
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<<The error I get is " no program associated with this file type".>>

 Are you sure as to the file type, that it's not .JPEG for example?

 Are you sure sDocFileNamePath is getting set properly?

 Really is no reason for Shell() itself to fail.   I would create a batch file with the statement, execute that from a command line and see if it fails.

Jim.

Avatar of Mel Brooks
Mel Brooks

ASKER

Richard.  Your code didn't work for me, but it did get headed in the right direction.  Here is what I did.  The ShellExecute was returning error 31 and the description I gave was that no file was associated with the file type.  So, if my code returned error 31,  I added this:

Select Case Right(sdocFileNamePath, 3)
      Case "jpg", "peg", "bmp", "png" "tif', "gif"
               Shell "MSPaint " & Chr(34) & sDocFileNamePath & Chr(34), vbNormalFocus
     Case Else
             msgbox "No program associated with this file type."
End Select