Full Version: Open Accde File Specifically In Access 2010 Runtime
UtterAccess Discussion Forums > Microsoft® Access > Access Q and A
kevinlaw
Hello UA,
I've got a small accde file that I use to update my FE. The Fe checks my website to see if there's an update available. If so, it opens the file 'updater.accde' and closes itself. Normally, this works great but if a user has an older version of Access (like 2007) it tries to open the 'updater.accde' file in that instead of the 2010 Runtime. This doesn't work (I thought an accde file should open even in 2007 but it doesn't- it was built in 2010 so maybe that's why) and it hangs up the updater from running.

In my shortcuts for the main FE and a manual Updater I have some code for opening it only in Access 2010 (this is through Sagekey's install wizard). It's only this automatic updater that the problem occurs- because it's not opened with the shortcuts, it's opened with code from the FE.

So is there a way, either in the code in the FE that opens the updater.accde file, or in the updater.accde file's own code, to make sure it opens ONLY in the Access 2010 Runtime that is installed?

Many thanks in advance!
Peter46
Obviously I don't know how you are executing your updater.accde but typically you must specfiy the path to the runtime msaccess.exe that you want to run it with.
kevinlaw
Hmm- would that path be the same on any computer (XP, Vista, 7, etc)? I would need the code to work this way on any particular installation.
theDBguy
Hi Kevin,

QUOTE (kevinlaw @ May 8 2012, 08:37 AM) *
In my shortcuts for the main FE and a manual Updater I have some code for opening it only in Access 2010 (this is through Sagekey's install wizard). It's only this automatic updater that the problem occurs- because it's not opened with the shortcuts, it's opened with code from the FE.

Couldn't you also create a shortcut with similar code for the updater.accde file?

Just my 2 cents... 2cents.gif
kevinlaw
Hi DBGuy,
I actually have a shortcut for the updater with that command in it- that's for if the user manually updates the FE. The problem is I want it to be seamless, meaning when and update is available it automatically closes the FE and opens the updater. The user doesn't have to do it themselves- just a single step removed but it makes a big difference to the ease of the experience (otherwise the user would have to go to the Start/Programs menu and find the updater shortcut, or clutter their desktop with another shortcut). It only hangs up if Access 2007 is installed. I was hoping to get around that somehow without having to use a manual shortcut.
theDBguy
Hi Kevin,

If the shortcut works, the user doesn't have to "manually" click on it, correct? You should be able to execute the shortcut from within your code using something like the ShellExecute() API.

Just my 2 cents... 2cents.gif
merlenicholson
I have a function that will return the executable path/name for any file extension. To use it: AccessExecutable = WhatsApp(".accde"). So this will give you the path of the installed Access executable.

Here's the Access code, with two caveats: 1) It works on all the 32-bit versions of Access, but needs to be modified to use the 64-bit API.

2) It needs a set of routines and constants for accessing the registry (see GetKeyValue). I've had those for many years - probably going back to Access 97 and I think it's been widely distributed. I'll supply those if you need them, but I can say this - I can't properly attribute the routines, and I didn't write them. And I don't want to violate any UtterAccess rules on this.

CODE
Public Function WhatsApp(ByVal Ext As String) As String
    Dim V As String
    Dim i As Integer
        If Not GetKeyValue(HKEY_CLASSES_ROOT, Ext, "", V) Then
            MsgBox "No value for " & Ext & ", Exiting"
            Exit Function
        End If
        If Not GetKeyValue(HKEY_CLASSES_ROOT, V & "\shell\open\command", "", V) Then
            MsgBox "No value for " & Ext & ", Exiting"
            Exit Function
        End If
        i = InStr(1, V, ".exe" & Chr(34))
        WhatsApp = Mid(V, 1, i + 5)
End Function



theDBguy
Hi Kevin,

Merle's post reminded me of this earlier topic:

Launching Correct Access Version

Just my 2 cents... 2cents.gif
kevinlaw
thanks Merle- much appreciated. I need to look into this a little to understand it but I'll give it a shot.
kevinlaw
Thanks for the link, DBGuy- I'll look into this and Merle's solution to see if I can get it to work. Much appreciated!
kevinlaw
Hi Merle,
I'm not quite sure how to implement this code. Would this be in a module and the WhatsApp function called in the autoexec? If so, is that all that would need to be done?
merlenicholson
You use the WhatsApp function - and the routine it's calling and declarations in a module. Save and compile. If all the references have been resolved and if it compiles, you're ready to use the WhatsApp function in a forms or modules VBA code, just like you would any built-in function. You've simply added a new function to VBA.

I'm including the entire module - everything you need, but this is just one of several registry functions in the set. Be sure to let me know if you have any problems compiling it and specifically what is missing. My own WhatsApp(".mdb") returns: "C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE". Office 2010 will be OFFICE14, not "OFFICE11".
If for some reason, someone is using Access 64-bit version, this needs to be modified to use the 64-bit Windows API.
CODE
Option Compare Database
Option Explicit

Public Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, ByRef phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
Public Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Public Const KEY_ALL_ACCESS = KEY_QUERY_VALUE + KEY_SET_VALUE + KEY_CREATE_SUB_KEY + KEY_ENUMERATE_SUB_KEYS + KEY_NOTIFY + KEY_CREATE_LINK + READ_CONTROL
' Reg Key ROOT Types...
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const ERROR_SUCCESS = 0                  ' Return Value...
Public Const REG_SZ = 1                         ' Unicode nul terminated string
Public Const REG_DWORD = 4                      ' 32-bit number

Public Function WhatsApp(ByVal Ext As String) As String
    Dim V As String
    Dim i As Integer
        If Not GetKeyValue(HKEY_CLASSES_ROOT, Ext, "", V) Then
            MsgBox "No value for " & Ext & ", Exiting"
            Exit Function
        End If
        If Not GetKeyValue(HKEY_CLASSES_ROOT, V & "\shell\open\command", "", V) Then
            MsgBox "No value for " & Ext & ", Exiting"
            Exit Function
        End If
        i = InStr(1, V, ".exe" & Chr(34))
        WhatsApp = Mid(V, 1, i + 5)
End Function

Public Function GetKeyValue(KeyRoot As Long, KeyName As String, SubKeyRef As String, ByRef KeyVal As String) As Boolean
' **********************************************
    Dim i As Long , rc As Long, hKey As Long, hDepth As Long, KeyValType As Long, tmpVal As String, KeyValSize As Long
    ' ********************************************
    rc = RegOpenKeyEx(KeyRoot, KeyName, 0, KEY_ALL_ACCESS, hKey) ' Open Registry Key
    If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError          ' Handle Error...
    tmpVal = String$(1024, 0)                               ' Allocate Variable Space
    KeyValSize = 1024                                       ' Mark Variable Size
    ' Retrieve Registry Key Value...
    '------------------------------------------------------------
    rc = RegQueryValueEx(hKey, SubKeyRef, 0, KeyValType, tmpVal, KeyValSize)    ' Get/Create Key Value
    If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError          ' Handle Errors
    If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then           ' Win95 Adds Null Terminated String...
        tmpVal = Left(tmpVal, KeyValSize - 1)               ' Null Found, Extract From String
    Else                                                    ' WinNT Does NOT Null Terminate String...
        tmpVal = Left(tmpVal, KeyValSize)                   ' Null Not Found, Extract String Only
    End If
    ' Determine Key Value Type For Conversion...
    '------------------------------------------------------------
    Select Case KeyValType                                  ' Search Data Types...
    Case REG_SZ                                             ' String Registry Key Data Type
        KeyVal = tmpVal                                     ' Copy String Value
    Case REG_DWORD                                          ' Double Word Registry Key Data Type
        For i = Len(tmpVal) To 1 Step -1                    ' Convert Each Bit
            KeyVal = KeyVal + Hex(Asc(Mid(tmpVal, i, 1)))   ' Build Value Char. By Char.
        Next
        KeyVal = Format$("&h" + KeyVal)                     ' Convert Double Word To String
    End Select
    GetKeyValue = True                                      ' Return Success
    rc = RegCloseKey(hKey)                                  ' Close Registry Key
    Exit Function                                           ' Exit
GetKeyError:    ' Cleanup After An Error Has Occured...
'------------------------------------------------------------
    KeyVal = ""                                             ' Set Return Val To Empty String
    GetKeyValue = False                                     ' Return Failure
    rc = RegCloseKey(hKey)                                  ' Close Registry Key
'------------------------------------------------------------
End Function




Marsupilami72
Maybe i´m thinking too simple - but have you ever tried renaming your 'updater.accde' to 'updater.accdr'?

The extension .accdr is assigned to the runtime...
kevinlaw
You know, that just might work. I hadn't thought of that- and simpler is almost always better. I'll give it a shot- thanks!
theDBguy
Hi Kevin,

I have my doubts (don't have the full and runtime versions installed at the same time to test it) but I hope it does work for you.

Good luck!
Marsupilami72
I tried it on my machine with Access 2010 installed - .accde starts Access, renamed to .accdr the same file starts the runtime.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.