Change column to Required = no and Drop all table relationships

J

Jim

What is the command to alter a 'required' column to be not required?

How do I drop all of the table relationships in a database if i do not know
the names assigned to the relationships?

Thanks in advance for the help,

Jim
 
D

Dirk Goldgar

Jim said:
What is the command to alter a 'required' column to be not required?

You can use DAO. Here's a quick & dirty version:

CurrentDb.TableDefs("YourTableName").Fields("YourFieldName").Required =
False
How do I drop all of the table relationships in a database if i do not
know
the names assigned to the relationships?

Do you want to drop *all* relationships of all tables? Or just all
relationships of a particular table?

'------- start of code ("air code") ------
Sub DropAllRelationships()

' Drop all relationships in the current database.
' Are you sure you want to do this?

Dim db As DAO.Database
Dim I as Long

Set db = CurrentDb

With db.Relations
For I = .Count - 1 To 0
.Delete .Item(I).Name
Next I
End With

End Sub

Sub DropTableRelationships(TableName As String)

' Drop all relationships involving a given table.

Dim db As DAO.Database
Dim I as Long

Set db = CurrentDb

With db.Relations
For I = .Count - 1 To 0
If .Item(I).Table = TableName _
Or .Item(I).ForeignTable = TableName _
Then
.Delete .Item(I).Name
End If
Next I
End With

End Sub
'------- end of code ------

The above is all air code, but should be close to correct. Warning -- use
with care, and have a backup!
 

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