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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if field exists in table 1

Status
Not open for further replies.

jammerdk

Technical User
Aug 16, 2001
51
DK
Hi Guys

I'm trying to figure out how to check if a given fieldname in user created table actually exists, and if doesn't hide the column in the table.

 
In a standard code module create the following function:
Code:
Function FieldExists(strTableName As String, strFieldName As String) As Boolean
On Error Resume Next
FieldExists = (CurrentDb.TableDefs(strTableName).Fields(strFieldName).Name = strFieldName)
End Function

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You can use ADOSchemas:

Code:
Function TableContainsField(SelectTableName, SelectFieldName) As String
'Works with linked tables
Dim cn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim strTempList As String

    Set cn = CurrentProject.Connection

    Set rs = cn.OpenSchema(adSchemaColumns, _
    Array(Empty, Empty, SelectTableName, SelectFieldName))

    If Not rs.EOF Then
         TableContainsField = "Yes"
    Else
         TableContainsField = "No"
    End If
End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top