Opening and Closing WinWedge in Access

Launching WinWedge

When you install WinWedge, a file association between the .SW3 filename extension and WinWedge.exe is created in Windows. This allows you to launch and activate WinWedge by executing (or double clicking on) a WinWedge configuration file. When you do this, WinWedge launches and loads the configuration file and then activates automatically with that configuration file.

To launch a WinWedge configuration file from an Access database automatically when you open the database in Access, you would first create a VBA module in your Access database with a function in it that launches your WinWedge configuration file. The following is an example of the code that you would put in the VBA module:

#If VBA7 Then
    Declare PtrSafe Function ShellExecute 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
#Else
    Declare Function ShellExecute 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
#End If

Public Const COMPort as String = "COM1" ' specify the COM port that WinWedge will be active on.

Sub LaunchWinWedge()
   'Determine the full path of the file – if no path specified then assume
   'the configuration file is in the same folder as this database
   OpenFile "WinWedgeConfigFile.SW3" ' or C:\FullPath\WinWedgeConfigFile.SW3
   
End Sub

Sub OpenFile(ByVal File As String)
   
   Dim FullPath As String, x As Long
   
   'Determine the full path of the file
   If InStr(File, "\") = 0 Then
      FullPath = CurrentProject.Path & "\" & File
   Else
      FullPath = File
   End If

   'Launch the configuration file
   x = ShellExecute(0, "open", FullPath, vbNullString, vbNullString, 0)
   
   'Prompt the user if launch fails
   If x < 33 Then
      MsgBox "The file: " & FullPath & " did not launch successfully"
   End If
    
End Sub

If you name a macro Autoexec, Access will automatically run the macro when you open the database.
To get the above function to run automatically when you open your database, you would create an Access Macro named Autoexec that performs the RunCode action and calls the above function named LaunchWinWedge().

Closing WinWedge

To close WinWedge, you would use the following function:

Function CloseWinWedge()
    Dim chan
    chan = DDEInitiate("WinWedge", COMPort)
    DDEExecute chan, "[AppExit]"
    DDETerminate chan
End Function

Unfortunately there is no “AutoClose” macro support in Access that you can use to call the above function when you close your database however you can create a hidden form that loads automatically when your database opens and then use the Form’s Unload event to call the CloseWinWedge function and thus shut WinWedge down automatically when you close the database.

Bonus Tip:

One of the options that you can set in  your WinWedge configuration file is to “Minimize on Activation” so that WinWedge will only appear in the system tray as an icon keeping it hidden from the user. To set this option in WinWedge Professional Edition, Run WinWedge.exe and select “File” – “Open” and open your WinWedge configuration file and then select “Activate” – “Minimize on Activation” and then select “File” – “Save” and “File” – “Exit”. In WinWedge Standard Edition, select “Define” – “Preferences” and check the check box labeled “Minimize on Activation”.

With the Minimize on Activation option selected, when you launch the WinWedge configuration file you will only see a small icon in the system tray area of the Windows taskbar. To open WinWedge you would right click on the WinWedge icon in the system tray and select “Open WinWedge” from the context menu that appears.

Contact Us