MS Access VBA - display dynamically built SQL results in datasheet subform

后端 未结 4 1577
长情又很酷
长情又很酷 2021-01-17 18:45

I have several years experience with VBA in MS Office applications (for automation and ETL processes) but have not had the need to mess with Forms in MS Access until recentl

4条回答
  •  梦毁少年i
    2021-01-17 19:27

    If the "object that is closed or doesn't exist" error occurs on the Me.dataDisplaySubform.Form.RecordSource line, chances are your subform control is not named dataDisplaySubform.

    You can examine the names of all your form's subform controls with this temporary change to your code ...

    'Me.dataDisplaySubform.Form.RecordSource = pSQL
    Dim ctl As Control
    For Each ctl In Me.Controls
        If TypeName(ctl) = "SubForm" Then
            Debug.Print ctl.Name, TypeName(ctl)
        End If
    Next
    Stop
    

    The Stop statement will trigger debug (break) mode and take you to the Immediate window where you can view the names of your form's subform control(s).

    The screenshot you added to the question confirms you're using the correct name for the subform control. However, that subform has nothing in its Source Object property. Since there is no form there, the second part of the error message, "doesn't exist", applies. There is no form to be referenced by Me.dataDisplaySubform.Form

提交回复
热议问题