Loop through the fields in a table to change a property

D

Damien

First of all, you are best off using DAO to interact with
your Access database's own objects, like its tables,
queries and fields. DAO is still the fastest way to
access a Jet database, apparently.

So, make sure your reference is set for DAO, then try:

Sub subChangeFields()

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set dbs = CurrentDb

Set tdf = dbs.TableDefs("table1")

For Each fld In tdf.Fields
fld.Required = False
Next

Set dbs = Nothing

End Sub


You'll be able to customise it to do what you want right ?

Let me know how you get on.


Damien
-----Original Message-----
Hello. I'm using VBA in Access XP with Win 2K.

1. Is there a way to loop through the fields in a table
using conventional VBA? It seems as though there should be
a way to do this without having to resort to ADO, DAO, or
SQL. I mean, Excel's object model includes the application
itself, file, sheet, range, etc. :)
2. Could someone please post example code on how to do
this, preferably using VBA, (but if necessary using ADO or
SQL) to change all fields in a table to accept nulls (i.e.
Required = No)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top