Example Databases for Businesses, Schools & Developers

Version 1.4                 First Published 1 Feb 2024                 Last Updated 6 Feb 2024


This article was inspired by a post by fellow MVP, Crystal Long, on LinkedIn.
Crystal has created her own version of the Windows Character Map app as an Access file: Unicode Character Map

I also find the Windows Character Map very useful and regularly use it whilst developing applications in Access.
In fact, its one of several apps I use so often that I include code to launch it direct fom Access using a keyboard shortcut, custom ribbon or the Quick Access Toolbar (QAT)

The example app included with this article includes code for running eleven apps I use most frequently with Access.

New Ribbon
Alternatively, frequently used apps can be pinned to the taskbar. However, this area can easily become over-crowded.

Taskbar


Download

Click to download:   RunExternalApps_v1.4      ACCDB file - approx 0.8 MB (zipped)


NOTE:
1.   Unzip the file then unblock to remove the 'Mark of the Web'. Run from a trusted location or click the Enable Content button
2.   The zip file also includes a UI file for re-creating the custom ribbon - see below for further information.


Version History

Version History
v1.2   1 Feb 2024 - Initial release
v1.4   6 Feb 2024 - added Speech Recognition function following prompt at Utter Access forum: Opening sapisvr.exe via VBA



Using the Example App

The app opens to a startup form:

Main Form
However, the custom ribbon, External Apps, is not automatically created when the file is opened on a new computer.
You could re-create this ribbon yourself, but to save you time, you can import it using the customisation file, Access Customisations.exportedUI included within the zip file.

To run this file, go to File . . . Options . . . Customise Ribbon OR right click on any blank space on an existing ribbon and select Customise the Ribbon

ImportUIFile
Select Import customisation file and browse to the location of the Access Customisations.exportedUI file. Select the file by clicking Open on the dialog box

FileOpen
A warning message appears.

MessageBox
Click Yes to confirm the import. The custom ribbon is added to the file:

Ribbon Imported
Another message will appear, warning that the app has to be restarted for the ribbon to become available. However doing this is probably unnecessary in this case

MessageBox2
You should now be able to run any of the external apps from the External Apps ribbon.
With two exceptions, the apps are all standard Windows apps and should be available at the specified path.

However, you will get an error message if Notepad++ or Word aren't installed or the install path is different.

MessageBox3


Modifying the app

All the code used to run each of the external apps is included in the module modShellEx. All procedures are functions so they can be run from an Autokeys macro.
No additional references are reuired to run this code which will work in 32-bit or 64-bit Access, version 2010 or later.

CODE:

Option Compare Database
Option Explicit

'Code originally by Dev Ashish for VBA6
'Checked/updated for VBA7 by Colin Riddington 05/03/2019

Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
      (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
      ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr

Dim lngPtr As Long     'CR - CHECKED & CORRECT in both 32-bit & 64-bit Access

'Call Wow64DisableWow64FsRedirection prior to calling ShellExecute and Wow64RevertWow64FsRedirection, immediately after.
'Disables file system redirection for the calling thread. File system redirection is enabled by default.
Private Declare PtrSafe Function Wow64DisableWow64FsRedirection Lib "kernel32.dll" (ByRef ptr As Long) As Boolean
Private Declare PtrSafe Function Wow64RevertWow64FsRedirection Lib "kernel32.dll" (ByRef ptr As Long) As Boolean

'--------------------------------------------------------------------------------

Public Sub ShellEx(ByVal Path As String, Optional ByVal Parameters As String, Optional ByVal HideWindow As Boolean)

      If Dir(Path) > "" Then
            ShellExecute 0, "open", Path, Parameters, "", IIf(HideWindow, 0, 1)
      Else             MsgBox "Can't find application"
      End If

End Sub

'code to run external apps e.g. from an Autokeys macro

'--------------------------------------------------------------------------------

Public Function OpenTabTip()

'Colin Riddington - Mendip Data Systems
'18/09/2018

'opens tablet screen keyboard in tablet mode
'To run it on a standard PC, disable the If ...End If lines

      'If modMetrics.System(SM_TABLETPC) Then
            #If Win64 Then
                  ShellEx "C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe", , True
            #Else
                  Call Wow64DisableWow64FsRedirection(lngPtr)
                  ShellEx "C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe", , True
                  Call Wow64RevertWow64FsRedirection(lngPtr)
            #End If
      'End If

End Function

'--------------------------------------------------------------------------------

Public Function HideTabTip()

'hides the tablet keyboard
      Call Wow64DisableWow64FsRedirection(lngPtr)
      ShellExecute 0, "open", "tskill", "TabTip", "", vbHidden
      Call Wow64RevertWow64FsRedirection(lngPtr)

End Function

'--------------------------------------------------------------------------------

Public Function OpenMagnifier()
      ShellEx "c:\windows\system32\magnify.exe", , 0
End Function

'--------------------------------------------------------------------------------

Public Function OpenNotepad()
      Shell "NOTEPAD.EXE", 1
End Function

'--------------------------------------------------------------------------------

Public Function OpenCharacterMap()
      Shell "CharMap.exe", 1
End Function

'--------------------------------------------------------------------------------

Public Function OpenCalculator()
      Shell "Calc.exe", 1
End Function

'--------------------------------------------------------------------------------

Public Function OpenPaint()
      Shell "mspaint.exe", 1
End Function

'--------------------------------------------------------------------------------

Public Function OpenSnippingTool()
      Shell "C:\Windows\Sysnative\SnippingTool.exe", 1
End Function

'--------------------------------------------------------------------------------

Function OpenSpeechRecognition()
      Dim result As LongPtr
      ' Path to the Speech Recognition app
      Dim appPath As String
      appPath = "C:\Windows\Speech\Common\sapisvr.exe"
      ' Command line arguments for the app
      Dim arguments As String
      arguments = "-SpeechUX"
      ' Execute the command
      result = ShellExecute(0, "open", appPath, arguments, vbNullString, vbNormalFocus)
End Function

'--------------------------------------------------------------------------------

Function OpenSystemSettings()
      ShellExecute 0, "open", "ms-settings:", vbNullString, vbNullString, vbNormalFocus
End Function

'--------------------------------------------------------------------------------

Public Function OpenWord()

On Error GoTo Err_Handler

      '64-bit Office in 64-bit Windows
      ' Shell "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE", 1
      '32-bit Office in 64-bit Windows
      Shell "C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE", 1

Exit_Handler:
      Exit Function

Err_Handler:
      If Err = 53 Then     'file not found
            MsgBox "Word is not available at the specified location", vbCritical, "Incorrect Path"
      Else
            MsgBox "Error " & Err & ": " & Err.Description
      End If
      Resume Exit_Handler

End Function

'--------------------------------------------------------------------------------

Public Function OpenNotepadPlus()

On Error GoTo Err_Handler
      Shell "C:\Program Files\Notepad++\notepad+++.exe", 1

Exit_Handler:
      Exit Function

Err_Handler:
      If Err = 53 Then     'file not found
            MsgBox "Notepad++ is not available at the specified location", vbCritical, "Incorrect Path or not installed"
      Else
            MsgBox "Error " & Err & ": " & Err.Description
      End If
      Resume Exit_Handler

End Function

'--------------------------------------------------------------------------------

Sub ShellNotepadPlus(sPathFile As String)
'open a named document to edit in NotePad++

On Error GoTo Err_Handler

      Shell "C:\Program Files\Notepad++\notepad++.exe " & sPathFile, 1

Exit_Handler:
      Exit Sub

Err_Handler:
      MsgBox "Error " & Err.Number & " in ShellNotepadPlus procedure : " & Err.Description, vbOKOnly + vbCritical
      Resume Exit_Handler

End Sub


Add similar functions for any additional external apps you do use regularly. Remove or disable any functions that you don't want to use.

Next edit the Autokeys macro to create a submacro and keyboard shortcut for any new apps you add. Delete any unwanted items.

AutokeysMacro
Finally add any new items to the External Apps ribbon.
First select commands from Macros, select the appropriate keyboard shortcut (if used), then Add to the custom ribbon.
Click Rename and choose a suitable name and icon from the available list of symbols. Finally, click OK

CustomizeRibbon
NOTE:
It isn't possible to add custom icons using this process.
However, you can instead create your own custom ribbon from scratch, giving you full control over both the appearance and functionality.

Yu can also use a similar process to add any customised ribbon items to the Quick Access Toolbar (QAT)



Summary / Conclusions

I hope this article will inspire you to create similar functionality for use in your own apps.

If you want to have the same functionality available in all your apps, you will need to:
a)   save any custom ribbons as exportedUI files for importing into your other apps
b)   import the module modShellEx

Alternatively, you can create a template file to include these items and use that for all new databases.
For more information, see my article: Application Parts and Templates



Feedback

Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.

Please also consider making a donation towards the costs of maintaining this website. Thank you



Colin Riddington           Mendip Data Systems                 Last Updated 6 Feb 2024



Return to Example Databases Page




Return to Top