I want to insert a field into the table, but before doing it I want to check if it exists.
Is it possible to check if the table contains certain field name?
The following will look at your table and then look a specific field and return the name. The "8" is the location you will need to adjust to your needs. You then could use something like If strName<> "MyFieldName" then ...
Dim strTable As String
Dim strName As String
strTable = "YourTable"
strName = dB.TableDefs(strTable).Fields(8).Name
Public Function fFindField(strTableName, strFieldName As String) As Boolean
Dim rst As New ADODB.Recordset
rst.Open CurrentProject.Connection.OpenSchema(adSchemaColumns, Array(Empty, Empty, strTableName, strFieldName))
fFindField = Not rst.EOF
End Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.