vba 在主窗体的子窗体中驱动 MS Access 查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12814810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:03:36  来源:igfitidea点击:

Driving a MS Access query in a subform form from the main form

vbacomboboxms-access-2010subforms

提问by KillerSnail

I have a subform in datasheet form.

我有一个数据表形式的子表单。

I want this subform to be filtered based on a combo box on the mainform. The data for the subform comes from a query. I have set the criteria of one of the fields of this query to be equal to:

我希望根据主窗体上的组合框过滤此子窗体。子表单的数据来自查询。我已将此查询的字段之一的条件设置为等于:

    [Forms]![Form_Data_Update]![cbo_ReportSelection]

The mainform is Form_Data_Update and the combo box is cbo_ReportSelection.

主窗体是 Form_Data_Update,组合框是 cbo_ReportSelection。

to make the subform refresh when I change the combo box I have put in

当我更改我输入的组合框时使子表单刷新

    Private Sub cbo_ReportSelection_AfterUpdate()
    DoCmd.OpenQuery ("Aggregate_Leanboard_Discipline_Grouping")
    End Sub

Is there an alternate way that does not result in the query opening up in a new tab? I want it to just refresh in the subform. I tried:

是否有另一种方法不会导致在新选项卡中打开查询?我希望它只是在子窗体中刷新。我试过:

    Me!Form_Leanboard_Discipline_Grouping_Subform.Requery

but that doesn't work i get an error '2465' Microsoft can't find the field 'Form_Leanboard_Discipline_Grouping_Subform'.

但这不起作用我收到错误“2465”Microsoft 找不到“Form_Leanboard_Discipline_Grouping_Subform”字段。

I am using Access 2010.

我正在使用 Access 2010。

Thanks

谢谢

采纳答案by HansUp

The subform is contained in a subform control. Use the name of the subform control, not the name of the form. They may have different names.

子窗体包含在子窗体控件中。使用子窗体控件的名称,而不是窗体的名称。他们可能有不同的名字。

Private Sub cbo_ReportSelection_AfterUpdate()
    Me!SubformControlName.Form.Requery
End Sub

回答by user2299546

I followed you guys and I got errors the coding that work for me was

我跟着你们,我遇到了错误,对我有用的编码是

Private Sub cbo_ReportSelection_AfterUpdate()

    Me.What ever Your SubForm Name.Requery

 End Sub

This is probably the same as whats above and if it is then delete but when i read the above comment it makes it seem like you would have to place "SubFormControl" in there some where.

这可能与上面的内容相同,如果然后将其删除,但是当我阅读上面的评论时,它看起来好像您必须将“SubFormControl”放在某个地方。

For the ones that doesn't know how to find the name of the sub form you go to the design view and left click the subform then properties in the ribbon the name of the Form would appear int eh properties tab on the right hand side of your screen.

对于那些不知道如何找到子表单名称的人,您可以转到设计视图并左键单击子表单,然后在功能区中的属性中,表单的名称将出现在右侧的属性选项卡中你的屏幕。

Also note the if your subform name has spaces you would have to place "_" where does spaces are.

另请注意,如果您的子表单名称有空格,则必须在空格所在的位置放置“_”。

Good Luck guys I consider myself as a rookie.. so i try to explain as much as i can for the other guy that would read this ten years after us... i need this code to complete a search bar in my access DB. I'm making a genealogy database for class and the first implementation is due today and this code just saved my ass from receiving and B to probably and A.. Thank You

祝你们好运,我认为自己是个菜鸟..所以我尽可能多地为另一个会在我们十年后读到这本书的人解释...我需要这个代码来完成我的访问数据库中的搜索栏。我正在为班级制作一个家谱数据库,第一个实现是今天到期,这段代码只是让我的屁股免于接收和 B 到可能和 A..谢谢