一直以來,Access數據庫中的申報數據在分公司與總公司之間傳遞,用Excel或DBase、TXT甚至Access等格式,我總覺得不太理想。最近看了一本書,不經意間發現了一個方法,使用Access數據庫生成申報數據與讀入數據似乎簡單了不少,特拿出來與大家分享。同時,也希望能得到更多的指點。
附上示例:
SubMwrite()
OnErrorGoTothiserr
DimrsAsNewADODB.Recordset
rs.Open"dlmd",CurrentProject.Connection,adOpenDynamic,adLockOptimistic,acTable
rs.Save"a:dlmd.adtg",adPersistADTG
rs.Close
Setrs=Nothing
thisexit:
ExitSub
thiserr:
MsgBoxErr.Description
Resumethisexit
EndSub
SubMread()
OnErrorGoToMerr
DimiAsInteger
DimrsDeAsNewADODB.Recordset
DimrsSoAsNewADODB.Recordset
rsSo.Open"a:dlmd.adtg","provider=mspersist"
rsDe.Open"dlmd",CurrentProject.Connection,adOpenKeyset,adLockOptimistic,acTable
DoUntilrsSo.EOF
rsDe.AddNew
Fori=0TorsSo.FIElds.Count-1
rsDe.Fields(i)=rsSo.Fields(rsDe.FIElds(i).Name)
Nexti
rsDe.Update
rsSo.MoveNext
Loop
rsSo.Close
rsDe.Close
SetrsSo=Nothing
SetrsDe=Nothing
Mexit:
ExitSub
Merr:
MsgBoxErr.Description
ResumeMexit
EndSub