toverholt
asked on
Fill PDF forms with Access data using JavaScript Code Question
I have some code that using ADBC connects to a db and gets data that I prepared programmatically prior to the opening of the PDF file.
My problem is that is doesn't close the object quick enough to fill in the form with new data. It takes some amount of time to time out and "disconnect" before you can open the PDF and fill the form again with new data.
The code is enclosed!
//------------------------ ---------- ---------- ---------- -------
//-----------------Do not edit the XML tags--------------------
//------------------------ ---------- ---------- ---------- -------
//<ACRO_Document-Level>
//<ACRO_source>Connect</AC RO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.Connec t ***********/
function Connect()
{
try
{
//app.alert("Attempting Connection ...");
dbConn = ADBC.newConnection(dbName) ;
if(dbConn == null)
throw "Error connecting to AcroTips";
stmtObj = dbConn.newStatement();
// Execute the SQL statement inside the database
stmtObj.execute(sqlToExecu te);
// Move the Result Set to the First Record Found
stmtObj.nextRow();
// The current row object
rowObj = stmtObj.getRow();
// Insert the values of the first Row of data into the
// form field values.
FillForm(rowObj);
// Let the user know that a connection was made.
//app.alert("Connected to Database");
}
catch(exc)
{
console.println(exc);
throw "Unable to Connect to Database";
}
}
//</ACRO_script>
//</ACRO_Document-Level>
//<ACRO_Document-Level>
//<ACRO_source>FillForm</A CRO_source >
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.FillFo rm ***********/
function FillForm(row)
{
this.getField("Name").valu e = row.Name.value;
this.getField("Address").v alue = row.Address.value;
this.getField("CSZ").value = row.CSZ.value;
this.getField("SS").value = row.SS.value;
this.getField("Age").value = row.Age.value;
this.getField("DOB1").valu e = row.DOB1.value;
this.getField("Today").val ue = row.Today.value;
this.getField("HomePhone") .value = row.HomePhone.value;
}
//</ACRO_script>
//</ACRO_Document-Level>
//<ACRO_Document-Level>
//<ACRO_source>FirstRecord </ACRO_sou rce>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.FirstR ecord ***********/
function firstRecord()
{
stmtObj.execute(sqlToExecu te);
stmtObj.nextRow();
rowObj = stmtObj.getRow();
FillForm(rowObj);
}
//</ACRO_script>
//</ACRO_Document-Level>
//<ACRO_Document-Level>
//<ACRO_source>ListDataBas es</ACRO_s ource>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.ListDa taBases ***********/
function ListDataBases()
{
var aList = ADBC.getDataSourceList();
console.show(); console.clear();
try
{
var DB = "", msg = "";
if (aList != null)
{
for (var i=0; i < aList.length; i++)
{
console.println("Name: "+aList[i].name);
console.println("Descripti on: "+aList[i].description);
// and choose one of interest
}
}
}
catch(exc)
{
console.println(exc);
}
}
//</ACRO_script>
//</ACRO_Document-Level>
//<ACRO_Document-Level>
//<ACRO_source>NextRecord< /ACRO_sour ce>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.NextRe cord ***********/
function nextRecord()
{
try
{
stmtObj.nextRow();
FillForm(stmtObj.getRow()) ;
}
catch(e)
{
}
}
//</ACRO_script>
//</ACRO_Document-Level>
//<ACRO_Document-Level>
//<ACRO_source>StartUP</AC RO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.StartU P ***********/
// Globals
var dbName = "WF2002";
var dbConn = null;
var stmtObj = null;
var sqlToExecute = "Select * from dotout";
var rowObj = null;
function Startup()
{
}
//</ACRO_script>
//</ACRO_Document-Level>
//<AcroForm>
//<ACRO_source>Fill In.ACRO_Annotation1.MouseU p.ACRO_Act ion1</ACRO _source>
//<ACRO_script>
/*********** belongs to: AcroForm.Fill In.ACRO_Annotation1.MouseU p.ACRO_Act ion1 ***********/
Connect();
//</ACRO_script>
//</AcroForm>
Troyo
My problem is that is doesn't close the object quick enough to fill in the form with new data. It takes some amount of time to time out and "disconnect" before you can open the PDF and fill the form again with new data.
The code is enclosed!
//------------------------
//-----------------Do not edit the XML tags--------------------
//------------------------
//<ACRO_Document-Level>
//<ACRO_source>Connect</AC
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.Connec
function Connect()
{
try
{
//app.alert("Attempting Connection ...");
dbConn = ADBC.newConnection(dbName)
if(dbConn == null)
throw "Error connecting to AcroTips";
stmtObj = dbConn.newStatement();
// Execute the SQL statement inside the database
stmtObj.execute(sqlToExecu
// Move the Result Set to the First Record Found
stmtObj.nextRow();
// The current row object
rowObj = stmtObj.getRow();
// Insert the values of the first Row of data into the
// form field values.
FillForm(rowObj);
// Let the user know that a connection was made.
//app.alert("Connected to Database");
}
catch(exc)
{
console.println(exc);
throw "Unable to Connect to Database";
}
}
//</ACRO_script>
//</ACRO_Document-Level>
//<ACRO_Document-Level>
//<ACRO_source>FillForm</A
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.FillFo
function FillForm(row)
{
this.getField("Name").valu
this.getField("Address").v
this.getField("CSZ").value
this.getField("SS").value = row.SS.value;
this.getField("Age").value
this.getField("DOB1").valu
this.getField("Today").val
this.getField("HomePhone")
}
//</ACRO_script>
//</ACRO_Document-Level>
//<ACRO_Document-Level>
//<ACRO_source>FirstRecord
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.FirstR
function firstRecord()
{
stmtObj.execute(sqlToExecu
stmtObj.nextRow();
rowObj = stmtObj.getRow();
FillForm(rowObj);
}
//</ACRO_script>
//</ACRO_Document-Level>
//<ACRO_Document-Level>
//<ACRO_source>ListDataBas
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.ListDa
function ListDataBases()
{
var aList = ADBC.getDataSourceList();
console.show(); console.clear();
try
{
var DB = "", msg = "";
if (aList != null)
{
for (var i=0; i < aList.length; i++)
{
console.println("Name: "+aList[i].name);
console.println("Descripti
// and choose one of interest
}
}
}
catch(exc)
{
console.println(exc);
}
}
//</ACRO_script>
//</ACRO_Document-Level>
//<ACRO_Document-Level>
//<ACRO_source>NextRecord<
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.NextRe
function nextRecord()
{
try
{
stmtObj.nextRow();
FillForm(stmtObj.getRow())
}
catch(e)
{
}
}
//</ACRO_script>
//</ACRO_Document-Level>
//<ACRO_Document-Level>
//<ACRO_source>StartUP</AC
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.StartU
// Globals
var dbName = "WF2002";
var dbConn = null;
var stmtObj = null;
var sqlToExecute = "Select * from dotout";
var rowObj = null;
function Startup()
{
}
//</ACRO_script>
//</ACRO_Document-Level>
//<AcroForm>
//<ACRO_source>Fill In.ACRO_Annotation1.MouseU
//<ACRO_script>
/*********** belongs to: AcroForm.Fill In.ACRO_Annotation1.MouseU
Connect();
//</ACRO_script>
//</AcroForm>
Troyo
You need to close your connection when you are done with it. Lookup the Connection object in the Acrobat JavaScript Scripting Reference document (from what I see in the code, I figure that you already have this document). You will find a close() method. Call this (on the connection to your DB) when you don't need it anymore (e.g. when the document gets closed).
ASKER
I was hoping for a little more direction.....like where to put the code. I am a HUGE vb geek, and MS Access geek. This area is new to me, and javascript still seems foreign to me, althought I muttered through this.
Troyo
Troyo
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.