Skip to main content

Search

Search

How Can I Disable/enable Bartenders Connected Database Using Vbscript

Comments

2 comments

  • Avatar
    Ian Cummings
    Moderator

    It is not possible to disable the database connection via VB script inside a BarTender document.  Perhaps the below example might help point the way...

     

    BarTender, in terms of its database connectivity, is a read-only application.  This means that in order to write back a value to a printed database record we will need to use BarTender's built-in VB Scripting capability.  Attached you will find a simple example which will do just that.  In the Excel file there are two fields, one for a product and the other which flags when the product's record has been printed.
     
    In the BarTender label format I have made 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")
    rs.open "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"
    rs.Update
     
     
    0
  • Avatar
    Legacy Poster

    thanks Ian, this looks like what I was after

    I have had a play with it this morning and with a few mods and adding a prompt for the product and a little change to the SQL I am able to update the product data with the value entered into the prompt.

    this shows me that I can update the record via the prompt screen

    I still need to add a new record, if the product name is not already one in the database, but but I think this should be possible and you have pointed me in the right direction

     

    thanks again 

    0

Please sign in to leave a comment.