To demonstrate a quick example you’ll need to download the example files acrotips.mdb, acrotips6006.pdf and AcroTips6006JS.txt. The example PDF has three buttons, one button connects to the database, and two other buttons to navigate the records in the sample database.
In the example database there is only one table ‘Customers’, there are five columns ‘CustomerID’, ‘FirstName’, ‘LastName’, ‘SSN’, ‘Comments’ and ‘Address’. These match the form fields with the same names.
I have also created three form buttons ‘Connect’, ‘First Record’ and ‘Next Record’.
For example there is a function to connect to the database called ‘Connect’ activated by the Connect button, there is also one for the First Record button called ‘firstRecord’ and also one for the Next Record button ‘nextRecord’.
Making a connection to a database is easy, you firstly need to create a Data Source Name [DSN] (Control Panel>ODBC/DataSources) – create a new DSN based on the Microsoft Access Database Driver, and select the ‘acrotips.mdb’ database.
For example in the Connect function you will see a line of code as follows:
dbConn = ADBC.newConnection('AcroTips');
‘AcroTips’ was the name of the DSN I created (note the case). Once we have the ‘connection’ to the database we can execute Structure Query Language (SQL) statements against it.
If you now click the ‘Connect’ button the PDF will have a connection to the sample database and will let you look through the records in the database by using the other two form buttons.
To summarise this tip, the basic steps required are:
- Create form fields to match those in your database.
- Make a Data Source Name (DNS) using control panel and select your database.
- Create an execute an SQL Statement