Export To Database Rather Than Importing 关注


I have seen similar questions but nothing that has helped me fully, I have created a shipping label , 99% of the data is input by the user at print , there is a "total" field I have used vb script to tally up. I have linked the database to the label but not to any objects as they obviously arent getting data from the db I want to be able to send the data to the DB after print.I am limited in my vbscript knowledge and would appreciate any help on this subject.

I have attached images of the lable and the database as I want the data to be input after print (The serial field is not part of the label so dont worry too much about that)

1 评论

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")

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"




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