我有一个(链接)表[Traffic],其中一个字段名为[Log]
我有一个变量IO,可以是“I”或“O”。VBA在Access中添加新记录
该函数的唯一目的是向包含一个字符串的[Log]列中的表[Traffic]添加一条新记录/行:每次结合“I”或“O”的日期标记表单被加载/卸载。
我尝试在Ms Access 2010中创建函数但未成功(错误:“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
您已经发布了EXCEL的代码,而不是ACCESS – 4dmonster 2014-08-28 13:25:32
在何处将数据添加到Access?我没有看到这一点。 – PaulFrancis 2014-08-28 13:33:59