These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Refreshing a data connection

Mr_Grump
Registered: Jul 17 2008
Posts: 27
Answered

Hi Everyone

I have a PDF form connected to an Access database. It's a simple database, single table with a list of peoples names. I use it to populate a few combo boxes. The reason I wanted to use the database was it would be easy for another user to edit the names in the drop-down lists.

I can add a name to the Access table and it shows up in the combo boxes as it should. The problem arises when I open the Access table and delete a name. When I open the PDF, the deleted name is still in the drop-down combo boxes.

The form is used across a LAN and I created a system DSN for the connection. I placed the code first in the form Initialize event and I've tried the Form Ready event for each combo box. Still same have the same problem.

I don't remember where I got the code but for the record, I'm not smart enough to create it myself. If someone could help me out I'd greatly appreciate it. Here's the code:

var sDataConnectionName = "DataConnection"; // example - var sDataConnectionName = "MyDataConnection";
var sColHiddenValue = "ID"; // example - var sColHiddenValue = "MyIndexValue";
var sColDisplayText = "Name"; // example - var sColDisplayText = "MyDescription"

// Search for sourceSet node which matchs the DataConnection name
var nIndex = 0;
while(xfa.sourceSet.nodes.item(nIndex).name != sDataConnectionName)
{
nIndex++;
}

var oDB = xfa.sourceSet.nodes.item(nIndex).clone(1);
oDB.open();
oDB.first();

// Search node with the class name "command"
var nDBIndex = 0;
while(oDB.nodes.item(nDBIndex).className != "command")
{
nDBIndex++;
}

// Backup the original settings before assigning BOF and EOF to stay
var sBOFBackup = oDB.nodes.item(nDBIndex).query.recordSet.getAttribute("bofAction");
var sEOFBackup = oDB.nodes.item(nDBIndex).query.recordSet.getAttribute("eofAction");

oDB.nodes.item(nDBIndex).query.recordSet.setAttribute("stayBOF", "bofAction");
oDB.nodes.item(nDBIndex).query.recordSet.setAttribute("stayEOF", "eofAction");

// Clear the list
this.clearItems();

// Search for the record node with the matching Data Connection name
nIndex = 0;
while(xfa.record.nodes.item(nIndex).name != sDataConnectionName)
{
nIndex++;
}
var oRecord = xfa.record.nodes.item(nIndex);

// Find the value node
var oValueNode = null;
var oTextNode = null;
for(var nColIndex = 0; nColIndex < oRecord.nodes.length; nColIndex++)
{
if(oRecord.nodes.item(nColIndex).name == sColHiddenValue)
{
oValueNode = oRecord.nodes.item(nColIndex);
}
if(oRecord.nodes.item(nColIndex).name == sColDisplayText)
{
oTextNode = oRecord.nodes.item(nColIndex);
}
}

while(!oDB.isEOF())
{
this.addItem(oTextNode.value, oValueNode.value);
oDB.next();
}

// Restore the original settings
oDB.nodes.item(nDBIndex).query.recordSet.setAttribute(sBOFBackup, "bofAction");
oDB.nodes.item(nDBIndex).query.recordSet.setAttribute(sEOFBackup, "eofAction");

// Close connection
oDB.close();

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The code you're showing is for the "Data DropDown" in the "Customize" tab of the components library.

Reopening the form causes the initialize code to run, which loads fresh data out of the AccessDB. The issue can't be on the Acrobat side. I've never had a problem with deleted records showing up. So the records must not have been turly deleted. Are you sure you're connecting to the correct DB, and that the records are really deleted. Maybe Access needs to be refreshed. When you close and then reopen the DB are the deleted records gone?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Mr_Grump
Registered: Jul 17 2008
Posts: 27
Thanks for replying and helping me out. This is a weird one. Is for me anyway. This morning I've tried several things and here's what I've discovered.

Your right about Acrobat. It's not the problem as I see it. I discovered that if I open the pdf in Livecycle, I can add a file and delete a file in the Access database and as long as I preview it in LiveCycle, all works well.

If I save the form, exit LiveCycle then edit the database, the changes won't show up in the pdf using Reader. This includes adding and deleting entries in Access. I confirmed their addition and deletion in the dbase and I tried extending rights in reader as well.

I decided to start from scratch. I deleted the database and created a new one. I deleted the data connection in the PDF and I deleted the System DSN.

I created a new System DSN using the Microsoft Access Driver (*mdb) since the form and database will reside in a LAN share.

I created a new data connection in the pdf then I had a thought..... I tried using Acrobat instead of Reader. It worked flawlessly so the issue must be with Reader even though I extended rights. I'm using version 9.1.3 of Reader. I did a repair action on Reader just in case.

After all this.... I still have the same problem.

Thanks for taking an interest....

Lane
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ahh, I missed that you were trying to use Reader. If you look in the console window in Reader you'll see that several errors are reported. Sorry, but it won't work. DB connections in Reader are only allowed with special Rights Enabling that has to be purchased from Adobe. Forget using Reader.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script