|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
设计一个员工上班打卡的excel小工具,当运行时,往数据库添加员工姓名和系统时间。以下是我写的VBA,用Office 2013的同事可以正常运行, Office2016的同事运行时会出现错误“Run-time error, Automation error ”,请教各位是哪里错了,非常感谢!
-------------------------------------------------------------------------
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim conn
Set conn = CreateObject("ADODB.Connection")
conn.Open (ThisWorkbook.GetConnectString)
conn.BeginTrans
Dim newstr As String
newstr = "Insert INTO Team_Check_In (NT_Name, CheckIn_Time) Values(N'" & Environ("Username") & "', getdate())"
conn.Execute (newstr)
conn.CommitTrans
conn.Close
MsgBox "Log in successfully"
Application.ScreenUpdating = True
End Sub
|
|