Setting the Record Source of a subform in Access

China☆狼群 提交于 2020-02-25 04:20:09

问题


Dim newRS
newRS = "SELECT DISTINCT [Grp_ID], [Group_Name], [Group_NPI] FROM [GROUP]"
Forms!loclistingfrm!LocationListSubFrm.RecordSource = newRS

When I look at the LocationListSubFrm sub form in Design View, there is no Record Source property. However, when I access it directly from the objects pane I can see it.

Is the fact that it's a subform preventing me from changing the record source? The same subform is recycled throughout my application, so I can't really edit it at the source.


回答1:


Do note, that you need to address the subform control, not the (sub)form itself:

Dim newRS As String

newRS = "SELECT DISTINCT [Grp_ID], [Group_Name], [Group_NPI] FROM [GROUP]"
Me!NameOfYourSubformControl.Form.RecordSource = newRS



回答2:


Try adding .form.recordsource as shown below.

Dim newRS
    newRS = "SELECT DISTINCT [Grp_ID], [Group_Name], [Group_NPI] FROM [GROUP]"
    Forms!loclistingfrm!LocationListSubFrm.form.RecordSource = newRS


来源:https://stackoverflow.com/questions/42168426/setting-the-record-source-of-a-subform-in-access

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!