TALtech Logo
search
Products Support Resources Free Software
  TALtech Home:  Support:  B-Coder Knowledge Base:  B-Coder DDE Examples


DDE Commands for Microsoft Access

The following example MS Access function demonstrates how to fill up a picture field (an OLE object field) in an MS Access database table with bar codes.

The function reads through the entire table and takes the source text for each bar code from a text field named "BarCodeText" and passes it to B-Coder. Next, it generates the bar code and saves the resulting bar code to disk as a .wmf (Windows MetaFile). Finally it inserts the image into the picture field named "BarCodePicture" in the same record as each "Barcode.txt" field.

The function below assumes that a table named "table1" is available that has at least two fields, one being a text field named "BarCodeText" (containing our source bar code text data) and another empty OLE object field named "BarCodePicture" (the destination for all bar code graphics).

After you get all your bar codes into your Access table as picture objects, you can print them in reports or however you want. Since this procedure also places the bar codes into the table as Windows MetaFiles instead of as bitmaps so you will get a much higher resolution printout and each graphic will use much less space in your database.

Function BarCodes ()

Dim Total As Long, Chan As Long, I As Long
Dim BCDirectory As String, MyTable As String
Dim MyBarCodeTextField As String, MyBarCodePictureField As String
BCDirectory = "C:\B-Coder3"
' Directory where B-Coder lives
MyTable = "table1" ' Name of Access table containing bar code data
MyBarCodeTextField = "BarCodeText" ' Field name containing the text for all bar codes
MyBarCodePictureField = "BarCodePicture" ' Name of the OLE (Picture) object field
' where bar codes are to be inserted
On Error Resume Next
Chan = DDEInitiate("B-Coder", "System")
' Establish link.
If Err Then ' If error occurs, B-Coder isn't running.
   Err = 0 ' Reset the error
   I = Shell(BCDirectory + "\B-Coder.exe", 7) ' and launch B-Coder.
   If Err Then Exit Function ' If another error occurs then exit.
   Chan = DDEInitiate("B-Coder", "System") ' else Establish link and continue.
End If
DDEExecute Chan, "[MESSAGEWARNINGS=OFF]" ' Turn off B-Coder warnings
DDEExecute Chan, "[PRINTWARNINGS=OFF]"
DoCmd.OpenTable MyTable, A_NORMAL ' Select our Access table
' Note: The syntax for all DoCmd statements in this function is correct for Access 97/2000.
' If you are using Access 2.0, change the period after all DoCmd statements
' to a single space character. i.e.  DoCmd OpenTable MyTable, A_NORMAL
Total = DCount("*", MyTable) ' How many data records in the table?
DoCmd.GoToRecord A_Table, MyTable, A_FIRST ' Go to the first record in the table
For x = 1 To Total ' Loop through each record
   DoCmd.GoToControl MyBarCodeTextField ' Select message text field
   DoCmd.DoMenuItem A_FORMBAR, A_EDITMENU, A_COPY, , A_MENU_VER20
   ' Copy to clipboard
   DDEExecute Chan, "[Paste/Build/Copy]" ' Pass it to B-Coder & build a bar code
   DoCmd.GoToControl MyBarCodePictureField ' Select the bar code picture field
   DoCmd.DoMenuItem A_FORMBAR, A_EDITMENU, A_PASTE, , A_MENU_VER20
   ' Paste in the bar code image
   DoCmd.GoToRecord A_Table, MyTable, A_NEXT ' Goto next record
Next ' Loop through all records
DDETerminate Chan ' Terminate the DDE link - all done!
End  Function

Back to Top

TALtech Home  |  Products  |  Resources  |  Free Software  |  Support  |  Buy Now  |  Register Your Products  | 
Site Map  |  Contact TALtech  |  News