Change column to Required = no and Drop all table relationships

  • Follow


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
0
Reply Utf 5/5/2010 2:00:01 PM

"Jim" <Jim@discussions.microsoft.com> wrote in message 
news:8F69F31B-5BB2-454A-9A0D-ECF3356B3E36@microsoft.com...
> 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!

-- 
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

0
Reply Dirk 5/5/2010 2:31:07 PM


1 Replies
340 Views

(page loaded in 0.046 seconds)

Similiar Articles:
















7/21/2012 9:54:21 PM


Reply: