Hi,
Thank you for your enquiry.
This is possible to achieve, but you will need to use database script functions. I have attached an updated version of my original sample along with a database to demonstrate how this can be achieved. I have tried to annotate the script functions as clearly as possible, but please let me know if you have any queries.
Please note that my database only includes questions whose answers begin with A, so this is the only cell you can click on at the moment. If you click on any other cell, a 'No questions found starting with' message appears, followed by the chosen letter. As the cell letters are displayed at random, you may find that the letter A is not available to test. If this is the case, simply exit and preview the publication again until you can see a cell containing the letter A. Of course, once you have set up a database containing questions of every letter, you may want to remove this error functionality, which you can achieve by deleting the following lines from the ShowQuestion() function:
Code:
//if no records have been returned (i.e; no questions exist for this letter)
if (num == 0) {
//select the entire contents of the Question_Text object
Question_Text.SetSelection(0,-1)
//replace selection with error message plus the chosen letter
Question_Text.ReplaceSelection("No questions found starting with " + cell)
//if records have been returned (i.e; questions do exist for this letter)
} else {
The function should now assume that questions exist for all letters and go straight ahead with the retrieval of a random question.
If you are unsure how to connect to a database using script, the following procedure should hopefully be of use:
- First, copy your existing Access .mdb file to the Desktop
- Launch Opus and create a blank new publication
- Click
File > Save As... and save the project to the Desktop with a filename of your choice
- Right-click on the page and select
Edit Actions- Select the
Triggers tab and open the
Synchronisation group of triggers
- Double-click on the
On Show trigger to apply it to the page
- Select the
Actions tab and open the
Database group of actions
- Double-click on the
Database Query action to apply it to the page
- Click the
Select button to display the list of available DSN files
- Click the
New... button to create a new DSN
- Select
Microsoft Access Driver (*.mdb) from the list of ODBC drivers and click Next
- Click the
Browse button to open the Save As dialog
- Open the
Save in drop-down list and select the Desktop from the top of the list
- In the File name field, type
test- When you are happy with the file name, click
Save- Click Next, then Finish. The ODBC Microsoft Access Setup dialog should now be displayed
- Click the
Select button. As the dialog defaults to the current location of the DSN file, you should see your .mdb file in the left-hand list
- Click on the .mdb file to highlight it, then click OK, OK and OK again to return to the Database Query settings
- If you minimise all open windows to display the Desktop, you will see that the test.dsn file has been created on the Desktop
- Go back into Opus, highlight the On Show trigger you applied to the page and press the Delete key on the keyboard to delete this trigger and its associated Database Query action
- Click OK to return to the main Opus workspace
- Now click
Insert > Script Object- In the script window, type the following:
Code:
myDB = new Database("FILEDSN=C:\\Documents and Settings\\USERNAME\\Desktop\\test.dsn;")
where
USERNAME is your Windows logon name. You can double-check this by opening Windows Explorer, navigating to the root of the C: drive and double-clicking on the Documents and Settings folder. A list of folders should appear corresponding to all of the users who are set up on the machine. Look for the folder which corresponds to your logon and make a note of the folder name (ensuring that you note any capitalisation or punctuation). Now go back into Opus and replace
USERNAME with the folder name you have noted.
On the second line of the script object, type:
Code:
records = myDB.ExecuteSQL("SELECT * FROM table;")
where
table is the name of the table in your database from which you wish to retrieve the records. To confirm this, double-click on your .mdb file to open it into Microsoft Access and make a note of the table name which appears below the three Create table... options (ensuring that you note any capitalisation or punctuation). Now go back into Opus and replace
table with this table name.
Now type the following two lines:
Code:
num_records = records.GetNumberofRecords()
Debug.trace(num_records)
Now preview the publication. A Script Debug window should pop up as soon as the page is displayed and display the number of records which have been retrieved from the database. This should match the number of rows you have added to your database in Microsoft Access.
All being well, go back into your script object, delete the Debug.trace() function and start coding your required SQL queries and actions.
You may notice that I have not included a DSN file with my publication and database. This is because I have 'embedded' the DSN information into the publication by clicking
Publication > Publication Properties > Database, selecting the DSN in the list and enabling the
Don't update data source option. This tells the publication to stop looking for a DSN file and instead locate the database within the directory from which it is running.
If you have any queries
Kind regards,