How to view a recordset in an access table by means of vba?

前端 未结 2 758
故里飘歌
故里飘歌 2021-01-07 03:41

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 t

2条回答
  •  有刺的猬
    2021-01-07 03:57

    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
    

    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 !

提交回复
热议问题