Questions? Search our site or call us at 1-800-722-6004

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:\Path\to\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

Categories: Macro / Code Sample, Microsoft Access, Data Collection, Serial (RS232), WinWedge

Last Updated: 2015.01.22

Need more help?

Don't hesitate to call or email us with your questions

Our office is open 9AM - 5PM Monday Through Friday (E.S.T.)

Technical Support: 215-496-0202

Toll-Free: 1 (800) 722-6004
Skype: taltech1 (Voice only)
Email: support@TALtech.com