|
Sub ghdw()
On Error Resume Next
Dim i&, ii&, jj&
res = MsgBox("准备添加当前的记录到数据库中!真要添加吗?", vbYesNo + vbQuestion, "添加记录")
If res = vbYes Then
Dim mydata As String, mytable As String
mydata = ThisWorkbook.Path & "\数据库.mdb"
mytable = "购货单位名称表"
Set myconnect = New ADODB.Connection
myconnect.ConnectionString = "provider=microsoft.jet.oledb.4.0;" _
& "data source =" & mydata & ";Jet OLEDB:Database Password=" & "810906"
myconnect.Open
Set myres = New ADODB.Recordset
myres.Open mytable, myconnect, adOpenKeyset, adLockOptimistic
ii = myres.RecordCount
i = Sheet5.[A16818].End(xlUp).Row
For iii = 1 To i
myres.AddNew
myres.Fields(1) = Sheet5.Cells(iii + 1, 1).Value
myres.Update
Next iii
ElseIf res = vbNo Then
If myres.BOF = True And myres.EOF = True Then
Exit Sub
Else
myres.MoveFirst
End If
Exit Sub
End If
End Sub
注意红字所在的位置(与原来的代码比较一下) |
|