我有一个按钮,它执行一些列出文件及其创建日期的 vba 代码。我对带有日期时间格式插入的 sql 插入感到困惑。该错误在 db.execute 时返回代码 128。有任何想法吗?
Do While Len(strFile) > 0
'Debug.Print strFolder & strFile
sSQL = "INSERT INTO tblVideos ( FileName , FileDate) VALUES ('" & strFile & "'," & Format(StrToDate(dateCreated(strFolder & strFile)), "\#yyyy-mm-dd hh:nn:ss\#") & ")"
Debug.Print sSQL
db.Execute sSQL, dbFailOnError
strFile = Dir()
Loop
end sub
Public Function StrToDate(strIn As String) As Variant
Dim var As Variant
Dim yr As Variant
If Len(strIn & "") Then
'StrToDate = CDate(Mid$(strIn, 3, 4) & "/" & Left$(strIn, 2) & "/" & Right$(strIn, 4))
var = Split(strIn, "/")
yr = Split(var(2), " ")
StrToDate = var(0) & "/" & var(1) & "/" & yr(0) & " " & yr(1)
Else
StrToDate = Null
End If
End Function