VBA添加新的logging到Access中的表

我有一个(链接)表[交通]与一个名为[日志]
我有一个variablesIO可以是“我”或“O”。

这个函数的唯一目的是在包含一个string的[Log]列的表[Traffic]中添加一个新的logging/行:每次载入表单时结合一个“I”或“O”的date标记/卸载。

我尝试在Ms Access 2010中创build一个函数,但没有成功(错误:“Object Required”)。

任何帮助,高度赞赏。

Public Function AppendTxt(IO As String) Dim sText As String Dim sTableName As String Dim col As Integer Dim lLastRow As Long Dim iHeader As Integer sTableName = "Traffic" sText = Format$(Now, "yyyy\-mm\-dd hhnn") & IO col = 0 With ActiveSheet.ListObjects(sTableName) 'find the last row of the list lLastRow = ActiveSheet.ListObjects(sTableName).ListRows.Count 'shift from an extra row if list has header If .Sort.Header = xlYes Then iHeader = 1 Else iHeader = 0 End If End With 'add the data a row after the end of the list ActiveSheet.Cells(lLastRow + 1 + iHeader, col).Value = sText End Function 

 Public Function Appendtxt(IO As String) Dim sql As String sql = "INSERT INTO tbl ( [timestamp], var ) " & _ "SELECT #" & Time() & "#, """ & IO & """ AS Expr2" DoCmd.RunSQL sql End Function 

假设你在这里发布一段excel代码时犯了一个错误,这应该是个诀窍。

编辑:摆脱任何警告消息,在数据库启动时调用以下函数。

 Function fncSetOptions() Application.SetOption "Confirm Action Queries", False Application.SetOption "Confirm Document Deletions", False Application.SetOption "Confirm Record Changes", False DoCmd.SetWarnings False End Function