如何通过VBA查看访问表中的记录集? [英] How to view a recordset in an access table by means of vba?

查看:234
本文介绍了如何通过VBA查看访问表中的记录集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在嵌入式访问vb编辑器的帮助下,我编写了一个小代码来分析数据库的字段值,并希望最终查看打开的访问内的表中的记录集.作为新手,我只能使用Debug.Print来显示字段名称.你们中的任何人都可以告诉我我可以使用哪些语句/命令来执行SQL String以便查看带有值的结果记录集吗?

With help of the embedded access vb editor i've written a small code to analyse the field values of my database, and want to finally view the recordsets in a table inside the opened access. As a newbie i can only use Debug.Print to display the field names. Could anyone of you tell me with which statements/commands i can execute my SQL String in order to view the result recordset with values?

Debug.Print FinalSQLString

推荐答案

据我所知,无法显示包含记录集的VBA实例的数据表.如果记录集的源是strQSL,则可以创建一个包含结果的表,然后打开该表,或者更优雅地创建queryDef并打开它:

As far as I know, there is no way to display a datasheet containing a VBA instance of a recordset. If the source of your recordset is strQSL, you could however create a table with your results, and open that one, or more elegantly, create queryDef and open it:

Sub ShowQd(strQdName As String, strSql As String)
'creates queryDef and display it in a datasheet'
    Dim qd As DAO.QueryDef

    Set qd = CurrentDb.CreateQueryDef(strQdName)
    With qd
        .ReturnsRecords = True
        .SQL = strSql
    End With
    DoCmd.OpenQuery strQdName
End Sub

如果您专注于显示事物,还可以将ListBox放在窗体中,将其Number of columns设置为查询返回的字段数(qd.Fields.Count),并将strSql设置为ListBox的RowSource . AND ...如果您将所有相关代码放在该表单中,则现在有了一个可以导入任何数据库中的表单,以快速显示所需内容:)
祝你好运!

If you focus on displaying things, you could also put a ListBox in a form, set its Number of columns to the number of fields returned by your query (qd.Fields.Count), and set your strSql as the RowSource of the ListBox. AND... if you put all your related code in that form, you now have a form that you can import in any db to quickly display what you want :)
Good luck !

这篇关于如何通过VBA查看访问表中的记录集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆