Fields.Refresh-Methode (DAO)
Gilt für: Access 2013, Office 2013
Aktualisiert die Objekte in der angegebenen Auflistung, um das aktuelle Schema der Datenbank wiederzugeben.
Syntax
Ausdruck . Aktualisieren
Ausdruck Eine Variable, die ein Fields-Objekt darstellt.
Hinweise
Verwenden Sie die OrdinalPosition-Eigenschaft der einzelnen Field-Objekte, um die Position zu bestimmen, die das Microsoft Access-Datenbankmodul für Field-Objekte in der Fields-Auflistung eines QueryDef-, Recordset- oder TableDef-Objekts verwendet. Eine Änderung der OrdinalPosition-Eigenschaft eines Field-Objekts führt möglicherweise erst beim Anwenden der Refresh-Methode zu einer geänderten Reihenfolge der Field-Objekte.
Verwenden Sie die Refresh-Methode in Umgebungen mit mehreren Benutzern, in denen andere Benutzer die Datenbank ändern können. Möglicherweise müssen Sie es auch für alle Sammlungen verwenden, die indirekt von Änderungen an der Datenbank betroffen sind. Wenn Sie beispielsweise eine Users-Auflistung ändern, müssen Sie möglicherweise eine Groups-Auflistung aktualisieren, bevor Sie die Groups-Auflistung verwenden.
A collection is filled with objects the first time it's referred to and won't automatically reflect subsequent changes other users make. If it's likely that another user has changed a collection, use the Refresh method on the collection immediately before carrying out any task in your application that assumes the presence or absence of a particular object in the collection. This will ensure that the collection is as up-to-date as possible. On the other hand, using Refresh can unnecessarily slow performance.
Beispiel
This example uses the Refresh method to update the Fields collection of the Categories table based on changes to the OrdinalPosition data. The order of the Fields in the collection changes only after the Refresh method is used.
Sub RefreshX()
Dim dbsNorthwind As Database
Dim tdfEmployees As TableDef
Dim aintPosition() As Integer
Dim astrFieldName() As String
Dim intTemp As Integer
Dim fldLoop As Field
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set tdfEmployees = dbsNorthwind.TableDefs("Categories")
With tdfEmployees
' Display original OrdinalPosition data and store it
' in an array.
Debug.Print _
"Original OrdinalPosition data in TableDef."
ReDim aintPosition(0 To .Fields.Count - 1) As Integer
ReDim astrFieldName(0 To .Fields.Count - 1) As String
For intTemp = 0 To .Fields.Count - 1
aintPosition(intTemp) = _
.Fields(intTemp).OrdinalPosition
astrFieldName(intTemp) = .Fields(intTemp).Name
Debug.Print , aintPosition(intTemp), _
astrFieldName(intTemp)
Next intTemp
' Change OrdinalPosition data.
For Each fldLoop In .Fields
fldLoop.OrdinalPosition = _
100 - fldLoop.OrdinalPosition
Next fldLoop
Set fldLoop = Nothing
' Print new data.
Debug.Print "New OrdinalPosition data before Refresh."
For Each fldLoop In .Fields
Debug.Print , fldLoop.OrdinalPosition, fldLoop.Name
Next fldLoop
.Fields.Refresh
' Print new data, showing how the field order has been
' changed.
Debug.Print "New OrdinalPosition data after Refresh."
For Each fldLoop In .Fields
Debug.Print , fldLoop.OrdinalPosition, fldLoop.Name
Next fldLoop
' Restore original OrdinalPosition data.
For intTemp = 0 To .Fields.Count - 1
.Fields(astrFieldName(intTemp)).OrdinalPosition = _
aintPosition(intTemp)
Next intTemp
End With
dbsNorthwind.Close
End Sub