比较字段MS-Access 2010 VBA

时间:2016-10-06 20:53:12

标签: vba ms-access ms-access-2010

我想比较条目表单下拉列表中的输入与我的DB列名称,如果匹配则为true,否则为false。 我在下面构建的函数只返回false。

输入:

tmp = DLookup("[Column Name]", "DB", "Val = '" & Forms![Entry Form]!DB.Value & "'")

功能:

Function FieldExist(ByVal strField As String) As Boolean
Dim TableSet As Object
Dim i As Integer

Set TableSet = CreateObject("ADODB.Recordset")
TableSet.activeconnection = CurrentProject.Connection
TableSet.Open ("ContactList")

    For i = 0 To TableSet.Fields.Count - 1
        If strField = TableSet.Fields.Item(i).Name Then
        FieldExists = True
        Exit Function
    End If
Next i

FieldExists = False
End Function

我认为导致问题的函数中的行是strField变量的声明。即:

        If strField = TableSet.Fields.Item(i).Name Then

0 个答案:

没有答案