VBA如何访问Access?
使用AutoCAD VBA如何访问Access数据库?(如何打开,关闭,和定义Access查询的条件?) 是啊,有谁会啊,请教了 <P>1 VB编辑器菜单工具-〉引用,把ActiveX Data Objects 2.8选上,然后确定</P><P>2 编写连接代码</P>
<P>'指定数据库文件路径返回一个数据库连接对象Connection</P>
<P> Function GetConnection(DBPath As String) As Connection <BR> Dim conn As New Connection<BR> <BR> With conn<BR> .Provider = "Microsoft.Jet.OLEDB.4.0"<BR> .ConnectionString = DBPath<BR> .Open<BR> End With<BR> Set GetConnection = conn<BR>End Function</P>
<P>sub test() </P>
<P>dim conn as Connection</P>
<P>dim rs as RecordSet</P>
<P>dim SqlCmd as new Command</P>
<P>Set conn = GetConnection("F:\CAD\CadDataBase\CadDataBase.mdb")<BR> With SqlCmd<BR> .ActiveConnection = conn<BR> .CommandType = adCmdStoredProc '命令类型为存储过程,adCmdText是普通SQL语句<BR> .CommandText = "Validate" '指出在ACCESS中建立的查询的名称<BR> End With</P>
<P>rs = SqlCmd.Execute , Array(id,pwd) '给定查询所需要的参数 <BR>msgbox rs.Feilds("userName").value</P>
<P>rs.close</P>
<P>conn.close</P>
<P>end sub</P> 研究中……
页:
[1]