-
This will loop through all fields in a specific table:
[VBA]
Sub TableLoop()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
On Error GoTo ErrHandler
Set db = CurrentDb
Set tdf = db.TableDefs("tblTest")
For Each fld In tdf.Fields
' your code here
Next fld
ExitHere:
On Error Resume Next
db.Close
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Number & ": " & Err.Description
Resume ExitHere
End Sub
[/VBA]
If you want to perform the same actions on all tables you could do the following:
[VBA]
Sub TableLoop()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
On Error GoTo ErrHandler
Set db = CurrentDb
For Each tdf In db.TableDefs
' usually don't want to change system or temp tables
If LCase(Left(tdf.Name, 4)) <> "msys" And Left(tdf.Name, 1) <> "~" Then
For Each fld In tdf.Fields
' your code here
Next fld
End If
Next tdf
ExitHere:
On Error Resume Next
db.Close
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Number & ": " & Err.Description
Resume ExitHere
End Sub
[/VBA]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules