Opening and Closing WinWedge in Access

Launching WinWedge

Similarly as with the data collection code, you’ll need a macro defined in Access designated to run the subroutine LaunchWedge(). To trigger the code to start automatically upon opening up the database, your macro must be called “Autoexec”.

#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

Sub LaunchWinWedge()

   OpenFile "device.SW3" ' or C:\FullPath\device.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

Closing WinWedge

If you want to automatically close WinWedge when closing Access, perhaps tie it to an event that happens like a form close event.

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

Contact Us