首页 > 解决方案 > DAO.Recordset 返回表名而不是列值

问题描述

原帖在这里

只是想知道这里是否有人最近在 Access 2016/2019 中遇到过任何 DAO VBA 问题,其中相同的代码在 2007 年工作得很好。这个问题似乎在 6 月 10 日左右出现,但我似乎找不到任何 Windows 10/Office 2016/2019 Click-To-Run 更新与 DAO 参考特别相关。

编辑

这是原始代码,它在 Access 2016/2019 中提取表名,以代替 Access 2007 中的列值。此代码也用于提取 2016/2019 年的列值,但自 6 月 10 日以来就没有了, 2020:

'Declare stuff
DoCmd.SetWarnings False
Dim sReportType As String, sYear As String, SGroup As String, sGroupID As String, sGroupRptId2 As String
Dim sGLCode As String, sGLCodeStart As String, sGLCodeEnd As String
Dim sPeriod As String, sPeriodStart As String, sPeriodEnd As String
Dim sListInactiveAccts As String
Dim sRptTitleA As String
Dim sSQL As String
Dim DB As DAO.Database
Set DB = CurrentDb()
Dim Q As QueryDef
Set Q = DB.QueryDefs("G/L Trial Balance")
Dim localRS As DAO.Recordset, localRS2 As DAO.Recordset


'Determine year to use based on YearSelection drop-down

If Me.YearSelection = "Current year" Then 'If "Current Year" is selected, get the year of the current fiscal
    sSQL = "SELECT a FROM table WHERE (((table.b)=""A""));"
    Set localRS = DB.OpenRecordset(sSQL, dbOpenSnapshot)        

    sYear = localRS(0).Value        

    localRS.Close
ElseIf Me.YearSelection = "Prior year" Then 'If "Prior Year" is selected, ensure a year is entered in the "Prior Year:" text box
    If IsNull(Me.PriorYearInput) Then 'If there isn't one, go to text box and notify end user
        DoCmd.GoToControl "PriorYearInput"
        MsgBox "Please enter a year in the ""Prior Year:"" field."
        Exit Sub
    Else 'If there is one, use it!
        sYear = Me.PriorYearInput
    End If
End If    

MsgBox Me.YearSelection & ", " & sYear

标签: vbams-accesswindows-10

解决方案


推荐阅读