Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting Required Fields in an Access Database

Status
Not open for further replies.

bloodless

Programmer
Feb 26, 2003
1
US
I've got a tool i'm building, an HTA, that will open an Access database, list all of the tables and queries in it, and then based on user selection populate a list of fields in the table or query. The purpose is to provide a list of fields for a user to construct a simple SQL statement for use with another class I built for ASP page interaction for dummies (hahahaha).

Anywho, the only thing i'm really having trouble with is detecting if a field is required either some sort of key or any other way. I can get field name, field type, max size, etc, but not whether it is required or not.

I'm using an ADO Connection.

Any help would be appreciated!
 
You need to use ADOX and you MUST use OLE DB, ODBC won't support the below snippet.

Set oCat = CreateObject("ADOX.Catalog")
oCat.ActiveConnection="Provider=Microsoft.Jet.OLEDB.4.0...."
Set oTable = oCat.Tables("Table1")
For Each oField In oTable.Columns
WScript.Echo oField.Name & " is " & _
IIf(oField.Properties("Nullable"), "Not ", "") & "required"
Next
oCat.Close
Set oField = Nothing
Set oTable = Nothing
Set oCat = Nothing Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top