设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1244|回复: 2
打印 上一主题 下一主题

[查询] 如何在VBA中创建一个查询对象?

[复制链接]
跳转到指定楼层
1#
发表于 2006-3-18 21:04:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请问如何在VBA中用创建一个查询对象?


[此贴子已经被作者于2006-3-18 13:05:50编辑过]

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2006-3-18 21:32:00 | 只看该作者
Creating a Stored Query


The following listings demonstrate how to create a row returning, non-parameterized query.


DAO


Sub DAOCreateQuery()





    Dim db      As DAO.Database


    Dim qry     As DAO.QueryDef





   'Open the database


    Set db = DBEngine.OpenDatabase("C:\nwind.mdb")


   


    'Create query


    Set qry = db.CreateQueryDef("AllCategories", _


      "SELECT * FROM Categories")


        


    db.Close


   


End Sub





ADOX


Sub ADOCreateQuery()





    Dim cat     As New ADOX.Catalog


    Dim cmd     As New ADODB.Command


   


    ' Open the catalog


    cat.ActiveConnection = "rovider=Microsoft.Jet.OLEDB.4.0;" & _


        "Data Source=C:\nwind.mdb;"





    ' Create the query


    cmd.CommandText = "Select * FROM Categories"


    cat.Views.Append "AllCategories", cmd


   


    Set cat = Nothing


   


End Sub





In this example, because the SQL statement is a non-parameterized, row-returning query, the ADO Command object is appended to the ADOX Views collection. Note, that when using the Jet Provider, it is possible to append a Command object to either the Views or Procedures collection regardless of the type of query that is being created. However, if a query such as the one in this example is appended to the Procedures collection, then the Procedures and Views collections are re
3#
 楼主| 发表于 2006-3-19 22:31:00 | 只看该作者
感谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-16 18:50 , Processed in 0.092521 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表