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();
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