Sub SendQuery()
Dim chan, MyDb, MyQuery, strSend
'set
database
Set MyDb = CurrentDb()
'open
a table or query that holds the data you wish to
send
Set MyQuery = MyDb.OpenRecordset("Deliveries")
'Open
DDE Channel to WinWedge
chan = DDEInitiate("WinWedge", "COM2")
'point
to first record in the table/query
MyQuery.MoveFirst
Do
strSend = "" 'reset string between records
'Generate string to send
For i = 0 To MyQuery.Fields.Count - 1
strSend = strSend & MyQuery.Fields(i) & ","
Next
'trim off last comma and replace it with CR/LF
strSend = Left(strSend, Len(strSend) - 1) & vbCrLf
'send string
DDEExecute chan, "[SEND(" + strSend + ")]"
MyQuery.MoveNext 'point to next record in the query
Loop Until MyQuery.EOF 'while (we have not reached the
end of the table/query)
quit:
'close DDE channel and
clean up
DDETerminate chan
Set db = Nothing
Set chan = Nothing
End Sub |