Simple and uncomplicated SQL Insert Statement From Form Input Follow

xcentric (Drew)

To save my life I can not figure this out. I am certain it is something sooooo stupid that is wrong.

1. Document consists of a single form with a single text box, single template with a single text box, single vb script in the OnPrintJobEnd event.
2. The script connects to a sql server and is supposed to insert the value from the template text box which is from the forms input text box.
4. When clicking on the "Test Script" button in the script assistant editor, the "Sample Text" from the template text box is successfully inserted into the sql database. However, when previewing the label, the entered text from the form is not inserted and is blank. I know the form control is linked to the templace data souce because the entered text from the form appears on the label.
This seems a very trivial and simple task to perform. Any assistance is welcomed. I am dumfounded why it does not work as expected. Someone please save me from insanity. Script below.
'declare the variables
Dim Connection
Dim Recordset
'set the variables
var1 = "Static Text"
var2 = Format.Objects("Template_Object").Value
'create an instance of the ADO connection and recordset objects
Set Connection = CreateObject("ADODB.Connection")
Set Recordset = CreateObject("ADODB.Recordset")
Server   = "" ' Enter your server name here
Database = "" ' Enter your database name here
User     = "" ' enter your user ID here
Password = "" ' Enter your password here
'open the server connection
Connection.Open "Driver={SQL Server};Server=" & Server & ";Database=" & Database & ";Uid=" & User & ";Pwd=" & Password & ";"
'insert the data
SQL = "INSERT INTO table1 (field1,field2) VALUES ('" & var1 & "','" & var2 & "')"




Peter Thane

I believe it is because you are processing the command after the printing part has been completed and so you would need something OnPostPrompt or OnIdenticalCopies so it is actioned during the print operation itself.

Please sign in to leave a comment.