ADOX Column - Default value

Summerwind

Registered User.
Local time
Today, 11:52
Joined
Aug 25, 2005
Messages
91
I use a technique of building a local temporary table to be the source of various reports. I create these using ADOX and things work well. :)

However, I have a P&L report that needs a table with the default values set to zero when the the table is created.

Currently I run code to fill the table with zeros after it has been created and this works but isn't too sophisticated.

anyone know of a way to set the table's field to be default zero?

Thanks for any help.
 
If you have a look at the following quick bit of code, you can see how ADOX is used to get what you want. Run it, and you should see that one of the field/column properties is called Default. You can edit this property using ADOX.

Code:
Function a()

    Dim cn As ADODB.Connection
    Dim cat As ADOX.Catalog
    Dim tbl As ADOX.Table
    Dim prp As ADOX.Property
    Dim col As ADOX.Column


    Set cn = CurrentProject.Connection
    Set cat = New ADOX.Catalog
    Set tbl = New ADOX.Table
    Set col = New ADOX.Column
    
    Set cat.ActiveConnection = cn
    
    Set tbl = cat.Tables("tblInvoices")
    
    For Each col In tbl.Columns
        For Each prp In col.Properties
            MsgBox prp.Name & ": " & prp
        Next
    Next
    
    cn.Close
    
    Set col = Nothing
    Set tbl = Nothing
    Set prp = Nothing
    Set cat = Nothing
    Set cn = Nothing
    
End Function
 
Excellent!!

Thanks very much :-)
 

Users who are viewing this thread

Back
Top Bottom