一个Access数据库数据传递的实例方法

网络整理 - 07-26

使用Access数据库生成申报数据与读入数据的实例方法:

示例:


以下为引用的内容:
Sub Mwrite()
On Error GoTo thiserr
Dim rs As New ADODB.Recordset
rs.Open "dlmd", CurrentProject.Connection, adOpenDynamic, adLockOptimistic, acTable
rs.Save "a:\dlmd.adtg", adPersistADTG
rs.Close
Set rs = Nothing
thisexit:
Exit Sub
thiserr:
MsgBox Err.Description
Resume thisexit
End Sub
Sub Mread()
On Error GoTo Merr
Dim i As Integer
Dim rsDe As New ADODB.Recordset
Dim rsSo As New ADODB.Recordset
rsSo.Open "a:\dlmd.adtg", "provider=mspersist"
rsDe.Open "dlmd", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, acTable
Do Until rsSo.EOF
rsDe.AddNew
For i = 0 To rsSo.Fields.Count - 1
rsDe.Fields(i) = rsSo.Fields(rsDe.Fields(i).Name)
Next i
rsDe.Update
rsSo.MoveNext
Loop
rsSo.Close
rsDe.Close
Set rsSo = Nothing
Set rsDe = Nothing
Mexit:
Exit Sub
Merr:
MsgBox Err.Description
Resume Mexit
End Sub