Dim conn As ADODB.Connection
Dim strSql As String
strSql = "update 商品表 set 数量=数量+20 where name='香蕉'"
Set conn = OpenConnForAccess(App.Path & "\test.mdb")
RunTrans strSql
Public Function OpenConnForAccess(ByVal FileName As String) As ADODB.Connection
Dim AdoConn As New ADODB.Connection
With AdoConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Persist Security Info=False"
.Open
End With
Set OpenConnForAccess = AdoConn
End Function
Public Function RunTrans(ByVal tranSql As String, ByVal AdoConn As ADODB.Connection)
With AdoConn
.BeginTrans
.Execute tranSql
.CommitTrans
End With
End Function