- Create a Player table in a Microsoft Access database
- Create a new InfoPath form: Use New from Data Connection...
and bind it to the Player table.
- Add a field called CurrentRecordNumber of type
Whole Number (integer) to the Main data source of the form.
Your Main data source should now resemble the following figure:
Main data source of the InfoPath form.
- Add a table to the InfoPath form.
- Drag the CurrentRecordNumber field from the
Main data source, and drop it below the table.
- Drag the Player repeating group from the
dataFields node in the Main data source and drop it into the table;
use a Repeating Section with Controls to display the
records.
- Remove the border from the Repeating Section and
disable the possibility to insert and delete sections in its
Properties dialog box.
- Add 4 buttons below the repeating section in the table and label them
First, Previous, Next,
and Last.
- Modify the table and controls to resemble the following figure:
The InfoPath form in design mode.
- Add the following rule on the First button:
>
Set a field's value: CurrentRecordNumber = 1
This button will move the record pointer to the first record in the database
table.
- Add the following rule on the Last button:
>
Set a field's value: CurrentRecordNumber =
count(Player)
This button will move the record pointer to the last record in the database
table by counting the total amount of records in the Player
table.
- Add the following rule on the Previous button:
>
Set a field's value: CurrentRecordNumber =
CurrentRecordNumber - 1
This button will move the record pointer one position backwards in the
table.
Add the following condition for this rule:
>
CurrentRecordNumber > 1
This will prevent the record pointer to go backwards beyond the first
record.
- Add the following rule on the Next button:
>
Set a field's value: CurrentRecordNumber =
CurrentRecordNumber + 1
This button will move the record pointer one position forward in the table.
Add the following condition for this rule:
>
CurrentRecordNumber < count(Player)
This will prevent the record pointer to go forward beyond the last record.
- Since you want to populate the fields on the InfoPath form with data
from the player at the current record position, you need to filter the data
being shown by the repeating section as follows: Double-click on the
repeating section to open its Properties dialog box. Click
on the Display tab. Click on the Filter Data...
button. Add a Condition that says:
>
position() = ../../my:CurrentRecordNumber
Note: You will have to type in this expression yourself in the
Specify Filter Conditions dialog box by choosing The
expression from the first dropdown list box.
- To autofill the Main data source of the InfoPath form
with data as soon as it is opened, do the following: Go to Tools >
Form Options.... Click on the Open and Save tab.
Click on the Rules... button. Add an Action
that says:
>
Query using a data connection: Main connection
- Set the Default Value of the
CurrentRecordNumber field to 1, so that the first
record is shown immediately when the form is first opened.