Skip to main content



Export To Database Rather Than Importing


1 comment

  • Avatar
    Domingo Rodriguez

    BarTender, in terms of database connectivity, is a read only application. The attached example shows how you can e.g. update a certain record of an Excel spread sheet once an item has been printed.


    In the BarTender label format you will see a connection to the Excel file, which assumes it will be found in the "C:\Seagull" folder.  It uses a query to only find and therefore possibly print those products (records) that do not have the word "YES" in the "Printed" column. The select record at print time option is turned on allowing the user to select which of the records that have not been printed, are to be printed.

    During the print job the VB script contained in the object in red placed off the label, runs a section of code that connects to the Excel file, finds the record being printed and sets the "Printed" field to the value "YES" so that next time the user prints it will not be available in the select at print time dialog to choose.  The VB script is as follows:


    OnNewRecord event

    'Define the object names.


    dim objConn
    dim strConn
    dim rs

    'Define the database connection parameter constants.


    Const adOpenStatic = 3
    Const adLockOptimistic = 3
    Const adCmdText = &H0001


    'Connect to the Excel file.


    Set objConn = CreateObject("ADODB.Connection")

    objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Seagull\Fruits.xls';Extended Properties=""Excel 8.0;HDR=YES;"""


    'Create a record set of one record which is the current record being printed.

    Set rs = CreateObject("ADODB.Recordset") "SELECT * FROM [Sheet1$]", objConn, adOpenStatic, adLockOptimistic, adCmdText
    rs.Find "Product = '" & Field("Sheet1$.Product") & "'"


    'Set the "Printed" field of the record to be "YES" thus flagging it as having been printed.

    rs.Fields("Printed") = "YES"




    This is just a sample which will need to be modified for your own needs.


Please sign in to leave a comment.