数据类型不匹配导致编码问题

时间:2019-01-18 09:09:54

标签: access-vba

我遇到了运行时错误3464

此代码对于某些数据类型正常工作。当它遇到诸如引擎启动日期之类的数据格式的值时,它将显示运行时错误。

Public Function SearchForID(strTableToSearch As String, strColumnNameToSearch As String, strNewItemName As String) As Integer

    'Varialbes
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim StrValue As String

    'Assigning Database to the Variable db
    Set db = CurrentDb
    'Creating a Query to the Recordset
    Set rs = db.OpenRecordset("SELECT * FROM " & strTableToSearch & " WHERE " & strColumnNameToSearch & " = '" & strNewItemName & "'")
    'We need to check for the valid record set
    rs.FindFirst ("[" & strColumnNameToSearch & "] = '" & strNewItemName & "'")

    If rs.NoMatch Then
       SearchForID = 0
    'If the recordset exists
    Else
    'Returning the ID value to StrValue
        SearchForID = rs.Fields(0)

    End If

    rs.Close
    Set rs = Nothing
    Set db = Nothing

End Function

我希望所有数据类型都可以执行代码

0 个答案:

没有答案