如何用vba代码将access数据库连接求代码?
Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点,是 Microsoft Office 的系统程序之一。用vba代码将access数据库连接求代码,代码如下:
Sub FYMXDL()
Dim XQID As Integer
Dim JZID As Integer
Dim FYID As Integer
Dim FBXZ As String '分包性质
Dim DW As String
Dim SARR(1 To 31) As Double
Dim rst As New ADODB.Recordset
mYpath = ThisWorkbook.Path & "\jzfydata.accdb"
Set cONn = CreateObject("ADODB.Connection")
cONn.ConnectionString = "Provider=Microsoft.Ace.OleDB.12.0;Data Source=" & mYpath
cONn.ConnectionString = cONn.ConnectionString & ";Jet OLEDB:Database "
cONn.Open
XQID = Cells(3, 2).Value
JZID = Cells(3, 5).Value
'清空改小区-建筑的费用明细
Sql = "delete from fymxb where 小区ID=" & XQID & " AND 建筑ID = " & JZID
cONn.Execute Sql
Const kshh = 7
hh = kshh
Do While Cells(hh, 3).Value > 0
FYID = Cells(hh, 3).Value
FBXZ = Cells(hh, 11).Text
For i = 1 To 31
SARR(i) = Round(Cells(hh, 13 + i - 1).Value, 2)
Next i
Sql = Sql & "," & SARR(i)
Next i
Sql = Sql & " )"
cONn.Execute Sql
hh = hh + 1
Loop
End Sub