Tom van Stiphout <no.spam.tom7744@cox.netwrote in
news:rgduv2pmi2mk2rfihp8j58mkn5r33emasm@4ax.com:
Quote:
I want to indicate requiredness by setting the background color of the
control. Ideally I would call a sub in Form_Load to just do its thing.
>
Below is what I have so far, but I realize this is of limited use
because both Autonumber fields as well as Primary Key fields not
necessarily have their Required property set, while they are required
for the purpose of the Insert action.
>
It seems to find out if a field is an Autonumber or PK field can be
complicated.
Does anyone have a brilliant solution?
If you are using Access >=2000 and if you are talking single column
primary keys of the underlying tables these might help:
Public Function PrimaryKey$(ByVal TableName$)
PrimaryKey = CurrentProject.Connection.OpenSchema( _
adSchemaPrimaryKeys, Array(Empty, Empty, TableName)) _
..Collect("COLUMN_NAME")
End Function
Public Function IsPrimaryKey(ByVal ColumnName$, ByVal TableName$) As
Boolean
IsPrimaryKey = CurrentProject.Connection.OpenSchema( _
adSchemaPrimaryKeys, Array(Empty, Empty, TableName)) _
..Collect("COLUMN_NAME") = ColumnName
End Function
Public Sub Test()
'northwinds
Debug.Print PrimaryKey("Customers") 'CustomerID
Debug.Print IsPrimaryKey("CustomerID", "Customers") 'True
Debug.Print IsPrimaryKey("CustomerName", "Customers") 'False
End Sub
Then again I do so little in Access these days that I may be too out of
touch to understand your question.
I guess we could modify these for miltiple column primary keys if needed.