任何人都可以告诉我如何检查访问表上是否存在列

时间:2021-02-10 04:27:39

Can anyone tell me how to check if a column exists in a table from a separate access db but locally on the computer? After I check if it exists, if it does I want to add a column. I am not finding the right answers on here just yet.

任何人都可以告诉我如何从一个单独的访问数据库中检查一个列是否存在于计算机本地?在我检查它是否存在之后,如果是,我想添加一列。我还没有在这里找到正确的答案。

1 个解决方案

#1


0  

You didn't even bother trying anything but this one is easy so here have a freebie. Normally, freebies require sacrifice of sandwiches and coffees. You're welcome

你甚至不打算尝试任何东西,但这个很容易,所以这里有免费赠品。通常,免费赠品需要牺牲三明治和咖啡。别客气

Function FindColumn(strTableName As String, strColumnName As String) As Boolean
    Dim db As Database
    Set db = DBEngine.OpenDatabase("unc path to your database")
    On Error Resume Next
    Set fld = db.TableDefs(strTableName).Fields(strColumnName)
    If Err = 0 Then FindColumn = True
    Set fld = Nothing       
    db.Close
    Set db = Nothing
End Function

#1


0  

You didn't even bother trying anything but this one is easy so here have a freebie. Normally, freebies require sacrifice of sandwiches and coffees. You're welcome

你甚至不打算尝试任何东西,但这个很容易,所以这里有免费赠品。通常,免费赠品需要牺牲三明治和咖啡。别客气

Function FindColumn(strTableName As String, strColumnName As String) As Boolean
    Dim db As Database
    Set db = DBEngine.OpenDatabase("unc path to your database")
    On Error Resume Next
    Set fld = db.TableDefs(strTableName).Fields(strColumnName)
    If Err = 0 Then FindColumn = True
    Set fld = Nothing       
    db.Close
    Set db = Nothing
End Function