急!请教关于VBA与DAO的问题
本人在调用ACCESS数据库时,需解决如下问题:(一)在程序运行时获得数据库中数据表的数量和各数据表的名称。
(二)在程序运行时进行数据库的复制和单个数据表的复制。
给段程序最好。
急!请各位高手指点,本人万分感谢! Application.CurrentData.AllTables.Count
注意,这里也包含了隐藏表和系统表,如果要精确获得用户表的数量,最好遍历判断一下。
数据库表复制直接用SQL命令吧。最好把你遇到的问题描述清楚一点。 下面是我前几天做的一个Access的应用中的一部分,一个很标准的ADO数据存取程序,供你参考:
_____________________________________________________________
Private Sub Calc(bolMode As Boolean)<BR> Call Init<BR> <BR> Dim curTotalArea(20) As Long<BR> Dim curTotalFee(10) As Long
Set con = Application.CurrentProject.Connection<BR> Set rs = CreateObject("ADODB.Recordset")<BR> <BR> stSql = "SELECT * FROM [房屋结构类型]"<BR> rs.Open stSql, con, adOpenStatic<BR> <BR> i = 0<BR> While Not rs.EOF<BR> curType(i) = rs![结构类型]<BR> curFee(i) = CInt(rs![补偿标准])<BR> i = i + 1<BR> rs.MoveNext<BR> Wend<BR> <BR> rs.Close<BR> <BR> stSql = "SELECT * FROM [年限折旧标准]"<BR> rs.Open stSql, con<BR> <BR> i = 0<BR> While Not rs.EOF<BR> curYearBegin(i) = CInt(rs![竣工年限(开始)])<BR> curYearEnd(i) = CInt(rs![竣工年限(结束)])<BR> curRate(i) = CSng(rs![折旧比率])<BR> i = i + 1<BR> rs.MoveNext<BR> Wend<BR> <BR> rs.Close<BR> <BR> stSql = "SELECT * FROM [清违资料登记表] "<BR> stSql = stSql & "WHERE [地址] Not Like '%%环城%%' And [地址] Not Like '%%国道%%' And [地址] Not Like '%%红岩%%' And [地址] Not Like '%%床单%%' And [地址] Not Like '%%凯运%%' And [地址] Not Like '%%桐荫坪%%' And [地址] Not Like '%%东门北路%%'"<BR> stSql = stSql & "And [拆迁区内] = True ORDER BY [证号]"<BR> rs.Open stSql, con, adOpenKeyset, adLockOptimistic<BR> <BR> strMsg = "数据统计中..."<BR> varReturn = SysCmd(acSysCmdInitMeter, strMsg, rs.RecordCount)<BR> <BR> i = 0<BR> j = 0<BR> While Not rs.EOF<BR> i = i + 1<BR> varReturn = SysCmd(acSysCmdUpdateMeter, i)<BR> <BR> If Not IsNull(rs!) Then<BR> rs! = CSng(rs!) * curFee(getFee(rs!)) * curRate(getRate(rs!))<BR> curTotalArea(getFee(rs!)) = curTotalArea(getFee(rs!)) + CSng(rs!) * 100<BR> curTotalFee(getFee(rs!)) = curTotalFee(getFee(rs!)) + CSng(rs!)<BR> Else<BR> rs! = 0<BR> End If<BR> <BR> If Not IsNull(rs!) Then<BR> rs! = CSng(rs!) * curFee(getFee(rs!)) * curRate(getRate(rs!))<BR> curTotalArea(getFee(rs!)) = curTotalArea(getFee(rs!)) + CSng(rs!) * 100<BR> curTotalFee(getFee(rs!)) = curTotalFee(getFee(rs!)) + CSng(rs!)<BR> Else<BR> rs! = 0<BR> End If<BR> <BR> If Not IsNull(rs!) Then<BR> rs! = CSng(rs!) * curFee(getFee(rs!)) * curRate(getRate(rs!))<BR> curTotalArea(getFee(rs!)) = curTotalArea(getFee(rs!)) + CSng(rs!) * 100<BR> curTotalFee(getFee(rs!)) = curTotalFee(getFee(rs!)) + CSng(rs!)<BR> Else<BR> rs! = 0<BR> End If<BR> <BR> If Not IsNull(rs!) Then<BR> rs! = CSng(rs!) * curFee(getFee(rs!)) * curRate(getRate(rs!))<BR> curTotalArea(getFee(rs!)) = curTotalArea(getFee(rs!)) + CSng(rs!) * 100<BR> curTotalFee(getFee(rs!)) = curTotalFee(getFee(rs!)) + CSng(rs!)<BR> Else<BR> rs! = 0<BR> End If<BR> <BR> If Not IsNull(rs!) Then<BR> rs! = CSng(rs!) * curFee(getFee(rs!)) * curRate(getRate(rs!))<BR> curTotalArea(getFee(rs!)) = curTotalArea(getFee(rs!)) + CSng(rs!) * 100<BR> curTotalFee(getFee(rs!)) = curTotalFee(getFee(rs!)) + CSng(rs!)<BR> Else<BR> rs! = 0<BR> End If<BR> <BR> If Not IsNull(rs!) Then<BR> rs! = CSng(rs!) * curFee(getFee(rs!)) * curRate(getRate(rs!))<BR> curTotalArea(getFee(rs!)) = curTotalArea(getFee(rs!)) + CSng(rs!) * 100<BR> curTotalFee(getFee(rs!)) = curTotalFee(getFee(rs!)) + CSng(rs!)<BR> Else<BR> rs! = 0<BR> End If<BR> <BR> rs! = rs! + rs! + rs! + rs! + rs! + rs!<BR> <BR> rs.Update<BR> rs.MoveNext<BR> Wend<BR> Debug.Print "总记录条数:" & i<BR> rs.Close<BR> <BR> stSql = "SELECT * FROM [房屋结构类型] "<BR> rs.Open stSql, con, adOpenForwardOnly, adLockOptimistic<BR> <BR> While Not rs.EOF<BR> rs![总面积] = curTotalArea(getFee(rs![结构类型])) / 100<BR> rs![总补偿费] = curTotalFee(getFee(rs![结构类型]))<BR> rs.Update<BR> rs.MoveNext<BR> Wend<BR> rs.Close
varReturn = SysCmd(acSysCmdClearStatus)<BR>End Sub<BR>
页:
[1]