1. Select "DDE Server" from the "Mode" menu
in the Wedge. When the dialog box appears asking for a DDE Command
Destination Application, enter: "MSACCESS" as the
Application Name and the name of your open database (without the MDB
Extension) as the DDE topic.
Note: If you compile your Access database to an MDE file, then you will need to change the DDE Topic to the name of the MDE file including the MDE file name extension. For example, if you compile your database and create a MDE file named MyData.MDE, you will need to specify "MyData.MDE" for the DDE Topic. You do not need to include the file path for the MDE file and should only specify the file name with the MDE extension.
The above also applies to MDB files that are used with the Microsoft Access Runtime engine. For example, if you will be using your MDB file with the Access Runtime engine, then you will need to change the DDE Topic to the name of the MDB file including the ".MDB" file name extension.
2. Select "Input Record Structure" in the "Define" menu
and define the structure of the input data to WinWedge. When
you get to the final Window entitled "Input Record Definition
Editor", enter the string: [GrabData] as the
Field Postamble DDE Command after the last data field that
you have defined. This is a DDE command that will be sent
to MSACCESS after each data record is received by the Wedge.
3. Set up the rest of the Wedge as needed for your
serial device and then activate it.
MSAccess does not have a "GrabData" DDE
command so the first step is to create one. When you define
a macro
in an Access database, the name of the macro automatically
becomes a valid MSAccess DDE command for as long as the database
is open.
1. Create a new macro that performs the "RunCode" Action.
For the function name that is required by the RunCode action,
enter the name "GetWedgeData()". Save the
macro with the macro name "GrabData" and
finally, create a new module with a function named "GetWedgeData()" and
enter the following commands in the body of the function:
| |
Function GetWedgeData ()
'
Declare variables
Dim ChannelNumber,
MyData As Variant
'
open a link to WinWedge
ChannelNumber
= DDEInitiate("WinWedge", "Com1")
'
get data from field(1)
MyData = DDERequest(ChannelNumber, "FIELD(1)")
'
terminate the link
DDETerminate ChannelNumber
'
if no data then quit
If Len(MyData) = 0 Then Exit Function
'Data
from Field(1) in WinWedge is now in the variable "MyData".
The following code sets the value of Textbox1 on
Form1 to display the current WinWedge data.
Forms!Form1!Textbox1.SetFocus
Forms!Form1!Textbox1.Text = MyData
End Function |
The example above sets up the Wedge to issue a DDE command
consisting of the name of an Access macro (directly to
the
Access database that contains the macro) after each data record
is received from your serial device. The macro calls an Access
VBA function that performs a DDERequest back to the Wedge
and returns the contents of FIELD(1) to a variable named "MyData".
It then updates Form1 with the data.
Related Links
Launching And Terminating WinWedge
From Access
Collecting Data Directly into
a Table in an Access Database
Transmitting Variables Out The
Serial Port From Access |