Ben,

Some VBA Access code with DDE to MapBasic RemoteMessageHandler.
In this example I transfer the Active Datasheet in Access to an array in
MapBasic:

Public Function ButtonGetQuery()

Dim objDatasheet As Object
Dim rs As DAO.Recordset
Dim i As Integer

    Const conNoActiveDatasheet = 2484
    On Error GoTo GetSelection_Err

    Set objDatasheet = Screen.ActiveDatasheet
    Set rs = objDatasheet.Recordset
    'MsgBox objDatasheet.Name

    i = 0
    rs.MoveFirst
    Do Until rs.EOF
        i = i + 1
        ReDim Preserve arrGeocodeQuery(i)
        arrGeocodeQuery(i) = rs!Geokode
        'MsgBox arrGeocodeQuery(i)
        rs.MoveNext
    Loop

    Set objDatasheet = Nothing
    Set rs = Nothing

    '-------------------------------------------
    'DDE RUTINE FOR DATASHEET
    '-------------------------------------------

    Dim nChannel_1 As Long
    Dim nChannel_2 As Long
    Dim szPathMBX As String
    Dim szEye As String

    szEye = Chr(34)

    On Error Resume Next

    '--------------------
    '*n c h a n n e l _ 1
    '--------------------

    '*establish link to mapinfo
    nChannel_1 = DDEInitiate("MapInfo", "System")

    '*if mapinfo not running
    If Err.Number <> 0 Then
        Err = 0

        '*run the mbx program; Laptop
        'Shell "C:\Programmer\MapInfo\Professional60DK\mapinfow.exe " & " "
& _
        '    "D:\mapbasic\FynsAmt\Program\MB_Natur.MBX", 1

        '*run the mbx program; Stationary
        Shell "C:\Programmer\MapInfo 6.0 DK\Professional\mapinfow.exe " & "
" & _
            "D:\mapbasic\FynsAmt\Program\MB_Natur.MBX", 1

        '*if another error, exit
        If Err Then Exit Function

        '*establish mapinfo link
        nChannel_1 = DDEInitiate("MapInfo", "System")
    End If

    '*MB strings to mapinfo
    'DDEExecute nChannel_1, "set window message position (1,1)"
    'DDEExecute nChannel_1, "Print Chr$(12)"

    '--------------------
    '*n c h a n n e l _ 2
    '--------------------

    '*try to establish link to mbx
    nChannel_2 = DDEInitiate("MapInfo", "MB_Natur.mbx")

    '*if no mbx in mapinfo then run it
    If nChannel_2 = 0 Then

        szPathMBX = "D:\mapbasic\FynsAmt\Program\MB_Natur.mbx"

        DDEExecute nChannel_1, "Run Application " & szEye & szPathMBX &
szEye

        '*establish link to mbx
        nChannel_2 = DDEInitiate("MapInfo", "MB_Natur.mbx")

    End If

    '*transfer geokode(s) to remote mbx handler
    'send the size of array to mb
    DDEExecute nChannel_2, "%" & UBound(arrGeocodeQuery)
    'MsgBox "dde loop..."
    For i = 1 To UBound(arrGeocodeQuery)
        DDEExecute nChannel_2, "�" + arrGeocodeQuery(i)
       'MsgBox "arr: " & i & " : " & arrGeocodeQuery(i)
    Next
    'zero the loop variable in MB
    DDEExecute nChannel_2, "#"
    'Close Form_Lokalitet

   'this make MI the front application, see the api call to use from MB in
a c. 7 dayes old Mapinfo-L message
    DDEExecute nChannel_2, "Call MIfront"

    DDETerminate nChannel_1
    DDETerminate nChannel_2

    Exit Function

GetSelection_Bye:
    MsgBox "None active datasheet to transfer to MapInfo..."
    Exit Function
GetSelection_Err:
    If Err = conNoActiveDatasheet Then
        Resume GetSelection_Bye
    End If

End Function

***********************
***********************
And the RemoteMessageHandler in  MB:
***********************
***********************

Sub RemoteMsgHandler

  szRemoteGeocode = CommandInfo(CMD_INFO_MSG)

  Do case szRemoteGeocode
    Case "Call MIfront"
      Call APISetMIFront
      Exit Sub
    Case "#"
      VBA zero loop variable when array dde as single string
      ix = 0
      Exit Sub
    Case Left$(szRemoteGeocode,1) = "%"
      nArrSize = Val(Right$(szRemoteGeocode,Len(szRemoteGeocode)-1))
      Exit Sub
    Case Left$(szRemoteGeocode,1) = "�"
      'String from array in Access VBA
      ix = ix + 1
      ReDim arrFromAccess(ix)
      arrFromAccess(ix) = Right$(szRemoteGeocode,Len(szRemoteGeocode)-1)
      Print "arrFromAccess("+ix+") i case: " + arrFromAccess(ix)
      'if arr is filled up again
      If nArrSize = Ubound(arrFromAccess) Then
        'Move to Sub Go when array filled up
        Call Go
     End If
  End Case
End Sub

*********
As you see I use some prefixes like %, * .... to tell the RemoteMsgHandler
whats delivered from access.

Hope this gets you on the way,
Jakob Lanstorp, Computing Geologist

Kampsax   GIS Software & Solutions, Rugaardsvej 55, 5000 Odense, DK
tel: + 45 63 13 50 13, dir: + 45 63 13 50 11, fax: + 45 63 13 50 90
mailto:[EMAIL PROTECTED] , http://www.kampsax-gis.dk, http://www.kampsax.dk
Authorized MapInfo Partner & Distributor in Denmark and Norway
***Visit http://www.kortal.dk and see Denmark from above


                                                                                       
                                        
                    Ben Crane                                                          
                                        
                    <[EMAIL PROTECTED]>                 Til:    
[EMAIL PROTECTED]                             
                    Sendt af:                            cc:                           
                                        
                    [EMAIL PROTECTED]        Vedr.:  MI-L Access and 
MapInfo DDE                                   
                    onsmag.com                                                         
                                        
                                                                                       
                                        
                                                                                       
                                        
                    30-01-02 16:49                                                     
                                        
                    Besvar venligst til Ben Crane                                      
                                        
                                                                                       
                                        
                                                                                       
                                        




> Hi list,
>
> boy, I've been busy...okay, I have an editing tool
> that now works. BUT, what I need to to pass record
> content from Access to MapInfo MBX file. I have
> managed to request information (sql string) from
> access before, but I'm kinda confused on what to do.
>
> In access I need to initiate a DDE with Mapinfo MBX,
> then DDEPoke the record content through to the MBX.
> What do I need my MBX to be able to do? DO I need a
> DDERequest to receive the info or will I use a
> remotemsghandler? If anyone has any code examples I
> would be grateful.
>
> In a sense, the Access user will press a button and
> this will pass the current record to MapInfo, which
> will then match this record in a table and center
> the
> map on the selected record...I can do this from
> MapInfo, but am battling by sending it from Access
> (if
> that makes any sense :)
>
> Thanx again list
> Ben
>







_______________________________________________________________________
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, send e-mail to [EMAIL PROTECTED] and
put "unsubscribe MapInfo-L" in the message body.

Reply via email to