Question: How do I initiate a DDE link to GeoLocator from MS Access 2000?
Answer: Use the following Access Visual Basic function.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO ' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A ' PARTICULAR PURPOSE. ' ' (c) Copyright 2000 Map Solutions. All rights reserved. ' ' Function: GeoLocatorDDE - Send command to GeoLocator via DDE ' Input: Cmd - MapDirector command string ' Returns: False - OK ' True - Error has occurred ' Revised: 2/21/00Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As LongOption Explicit Option Compare DatabasePublic Function GeoLocatorDDE(ByVal Cmd As String) As BooleanDim intI As Integer, intChan1 As Long, intStatus As Integer Dim strTopics As String Dim WinmapDir As String Dim iFile As Integer Dim bRet As Boolean Dim Timeout, StartTime Dim hModConst TimeoutInterval As Integer = 20 ' Time to wait for GeoLocator (seconds)On Error Resume Next ' Handle our own errorsWinmapDir = Space(128) Timeout = False bRet = False' Locate GeoLocator folder intStatus = GetPrivateProfileString("WINMAPS", "APPDIR", "C:\WINMAPS", WinmapDir, Len(WinmapDir), "winmaps.ini") WinmapDir = Mid(WinmapDir, 1, intStatus)' Establish Link to GeoLocator server intChan1 = DDEInitiate("WinMap", "Command")' If error occurs, GeoLocator may not be running. If Err.Number <> 0 Then Err.Clear ' Clear errors' Create GeoLocator Alternate Configuration File iFile = FreeFile Open "dde.cfg" For Output As iFile' Create flag file when GeoLocator ready Print #iFile, "Notify.1 = CreateFile dde.ok" Print #iFile, "GeoProg.AddMetaClass = Markers" Print #iFile, "GeoProg.AddClass = Marker" Close iFile' Start GeoLocator with empty map data file Kill ("result.mdf") hMod = Shell(WinmapDir + "\Winmap.exe -A dde.cfg result.mdf", 1)' Wait for GeoLocator to initialize If (Abs(hMod) = 0 Or Abs(hMod) > 32) Then StartTime = Time Err.Raise 1 iFile = FreeFile While Err.Number <> 0 And Not Timeout DoEvents ' Let other task run If DateDiff("s", StartTime, Time) > TimeoutInterval Then Timeout = True ' Time has expired End If Err.Clear ' Clear errors Open "dde.ok" For Input As iFile ' Has GeoLocator created flag file? Wend Close iFile Kill ("dde.ok") ' Clean up flag fileErr.Clear ' Clear errors If Not Timeout Then ' Establish GeoLocator link. intChan1 = DDEInitiate("WinMap", "Command") If Err.Number <> 0 Then MsgBox ("Could not initiate GeoLocator link") End If Else MsgBox ("GeoLocator not responding") End If Else MsgBox ("Cannot start GeoLocator") End If End If ' Diagnostic message ' MsgBox "Err = " & Err & " Timeout = " & Timeout' Send commands to GeoLocator if link was established If Err.Number = 0 And Not Timeout Then DDEExecute intChan1, Cmd Else bRet = True End If' Terminate DDE link DDETerminate intChan1' Return completion status GeoLocatorDDE = bRetEnd FunctionSub TestDDE() Dim strAddr Dim Cmd Dim iFile As IntegeriFile = FreeFile Open "testdde.mif" For Input As iFile ' Has GeoLocator created flag file? Line Input #iFile, strAddr Cmd = "LocateRecord" & " " & strAddr GeoLocatorDDE (Cmd) Close iFileEnd Sub