以下代码的功能是,通过PPT,使用VBA,将内容写入到ACCESS里面。
Private Sub CommandButton1_Click()
If DbCnct.State = adStateOpen And Not IsEmpty(adStateOpen) Then dbconnect.Close
DbCnct.Provider = "microsoft.jet.oledb.4.0"
DbCnct.ConnectionString = "test.mdb"
DbCnct.Open
If ReSet.State = adStateOpen And Not IsEmpty(adStateOpen) Then ReSet.Close
ReSet.Open "test", DbCnct, adOpenDynamic, adLockOptimistic
With ReSet
.Update '更新该记录,追加新纪录为AddNew,删除为Delete
.Fields("mingzi").Value = TextBox1.Text
.Fields("xingbie").Value = TextBox2.Text
.Fields("dizhi").Value = TextBox3.Text
ReSet.Update
End With
ReSet.Close
Set ReSet = Nothing
Set DbCnct = Nothing
End Sub
在真正应用中,还要考虑到记录数,记录移动等,但作为了解原理和入门,这些已经够了。