|
Private Sub CommandButton1_Click()
Dim RS1 As Recordset
Dim DB1 As Database
On Error GoTo 1000
Set DB1 = OpenDatabase(ThisWorkbook.Path & "\" & "数据库.mdb", False, False, ";pwd=888")
Set RS1 = DB1.OpenRecordset(Name:="人员信息", Type:=dbOpenDynaset)
With RS1
x = 0
Do While Sheet5.Cells(5, 1).Value <> ""
.AddNew
.Fields("客户名称").Value = Sheet5.Cells(5, 1).Value
.Fields("所属区域").Value = Sheet5.Cells(5, 2).Value
.Fields("负责人").Value = Sheet5.Cells(5, 3).Value
.Fields("所属部门").Value = Sheet5.Cells(5, 4).Value
.Fields("备注").Value = Sheet5.Cells(5, 5).Value
Sheet5.Rows(5).Delete
x = 1
Loop
If x = 0 Then
MsgBox "无效数据"
Else
MsgBox "数据已导入!"
End If
End With
DB1.Close
Exit Sub
1000:
MsgBox "无效数据"
DB1.Close
End Sub
程序正常运行,已弹出数据已经导入提示框,为什么在ACCESS中没有数据呢? |
|