Refresh or requery data
If you are sharing a database over a network, other users could be changing data while you are viewing the same data in a datasheet or form. Microsoft Office Access updates the data that you see at set intervals. However, you can immediately display the most current data by refreshing the records. You can also perform a more thorough update by requerying the data.
Refreshing records only updates the data that already exists in your datasheet or form. It does not reorder records, display new records, or remove deleted records and records that no longer meet specified criteria. To perform those tasks, you can requery the records. You can requery data manually, by using a macro, or by using code.
Note: Because requerying data does more than refreshing data, it takes longer, and can take quite a while depending on the recordset.
What do you want to do?
Refresh data
-
Do one of the following:
-
To refresh the records in Datasheet or Form view, on the Home tab, in the Records group, click Refresh All, and then click Refresh.
-
To refresh the records in PivotTable or PivotChart view, on the Design tab, in the Data group, click Refresh Pivot.
-
Set the refresh interval
You can set the interval at which Access refreshes data. By default, Access refreshes data every 60 seconds.
-
Click the Microsoft Office Button , and then click Access Options.
-
In the left pane of Access Options dialog box, click Advanced.
-
In the right pane, under Advanced, specify a value for Refresh interval (sec).
Manually requery data
-
Press SHIFT+F9.
Use a macro to requery data
If you want data to be requeried automatically when an event occurs, you can create a macro and attach it to the event. For example, suppose that you want to requery the data in a form whenever the form receives the focus. You could create a macro and attach it to the form's On Got Focus event, by using the following procedure:
-
On the Create tab, in the Other group, click Macro. If this command is unavailable, click the arrow beneath either the Module or the Class Module button, and then click Macro.
-
Click the arrow in the first cell under Action, and then click Requery.
-
Save the macro, using the name Requery, and then close the Macro Builder.
-
Open the form that you want in Design view. If the property sheet is not displayed, press F4 to display it.
-
Make sure that the form itself is selected. Then, on the property sheet, click the Event tab.
-
On the Event tab, click the arrow in the On Got Focus property, and then click the name of the macro — Requery.
-
Save the form.
Use code to requery data
You can also use code to requery data automatically. Suppose that you want to requery the data in a form whenever the form receives the focus. You could create a module and attach it to the form's On Got Focus event, by using the following procedure:
-
Open the form that you want in Design view. If the property sheet is not displayed, press F4 to display it.
-
Make sure that the form itself is selected. Then, on the property sheet, click the Event tab.
-
On the Event tab, in the On Got Focus property, click the Build button .
-
In the Choose Builder dialog box, click Code Builder.
A new module opens in the Visual Basic Editor.
-
Type Me.Requery, and then close the Visual Basic Editor.
-
Save the form.
No comments:
Post a Comment