Collecting Data Directly into a Form in Access

WinWedge DDE Server Settings

Remember to set WinWedge up in DDE Server Mode! Click here.

DDE Application Name: MSACCESS
DDE Topic: Database name (See below *)
DDE Command: GrabData

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.

Access 2007 and Newer: When specifying the DDE Topic in WinWedge, include the full name of the database file with the extension. For example: “MyData.ACCDB” without the quotes.

Access Instructions

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.

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.

Contact Us