Views:

Product: LABELVIEW Gold, CODESOFT Enterprise

Version: 2014 & Newer

 

 

1. Open Label Design and go to File > Properties > Visual Basic Scripting

 

2. From the dropdown, select Sub OnAfterPrintJob(ByVal Doc)
3. Insert the following script, making the appropriate changes to match your environment:

Dim ConnString
Dim SQL
Dim myConn
Dim MyCommand
DIM VARVALUE

VARVALUE = Document.Variables.Item("VAR1").Value()
SQL = "INSERT INTO [DATABASE].[dbo].[TABLE](COLUMN) VALUES('" & VARVALUE & "')"

ConnString="DRIVER={SQL Server};SERVER=(local)\SQLEXPRESS;UID=sa;" & _
"PWD=PASSWORD;DATABASE=DATABASE"


Set myConn = CreateObject("ADODB.Connection")
Set myCommand = CreateObject("ADODB.Command" )
myConn.Open ConnString
Set myCommand.ActiveConnection = myConn
myCommand.CommandText = SQL
myCommand.Execute
myConn.Close

Notes:
SQL = "INSERT INTO [DATABASE].[dbo].[TABLE](COLUMN) will need to be changed to match the database name, tables, and columns being used.

Var1 is the name of the data source on the label design that is being referenced. This can also be changed to fit environment.

ConnString="DRIVER={SQLServer};SERVER=(local)\SQLEXPRESS;UID=sa;"&_"PWD=PASSWORD;DATABASE=DATABASE" will also need to be changed to reflect proper server credentials.

4. The test button will confirm if the script is correct

5. Once completed, you can now print and the value in Var1 data source will be inserted into the specified database.