简体   繁体   English

显示来自选定列表框的访问子表单中的查询

[英]Display queries in access subform from a selected listbox

Within Access 2010, I am trying to make a form display a query within a subform QueriesSubForm that when selected from listbox QueryListBox and then click on the button runbtn .在 Access 2010 中,我试图让一个表单在子表单QueriesSubForm中显示一个查询,当从列表框QueryListBox选择时,然后单击按钮runbtn It is supposed to display the query within the linked subform, and change when you do this whole steps again from a different choice selected on the listbox and click on the button.它应该在链接的子表单中显示查询,并在您从列表框中选择的不同选项中再次执行整个步骤并单击按钮时进行更改。

At the moment I can only get it to work, if I want it to display the queries in a new task window, when programmed like so:目前我只能让它工作,如果我想让它在一个新的任务窗口中显示查询,当这样编程时:

QueriesListBox Listbox - SQL View QueriesListBox 列表框 - SQL 视图

SELECT MSysObjects.[Name]
FROM MSysObjects
WHERE (((MSysObjects.[Type])=5) AND ((Left([Name],1))<>"~"))
ORDER BY MSysObjects.[Name];

runbtn Button - VBA View runbtn 按钮 - VBA 视图

Private Sub runbtn_Click()
DoCmd.OpenQuery QueryListBox, acViewNormal
End Sub

It works and appears to just open one of the queries from the queries list and display it to me, which I do not want.它可以工作并且似乎只是从查询列表中打开一个查询并将其显示给我,这是我不想要的。

This might be an easy thing, but I can not see how it is done with either SQL, VBA or Macro, which I am guessing is need for this to work这可能是一件简单的事情,但我看不到它是如何使用 SQL、VBA 或宏完成的,我猜这是需要它来工作的

Ok, here's one way to do it.好的,这是一种方法。 First make sure your subform is set up with no source object.首先确保您的子表单设置为没有源对象。 Then setup your button click like so:然后像这样设置你的按钮点击:

Private Sub runbtn_Click()
    Me.QueriesSubForm.SourceObject = "Query." & QueryListBox.Value
End Sub

That should get you the result you're looking for.这应该会让你得到你正在寻找的结果。 Alternatively, if you want your form to open with a certain query to displayed on open, you could set up your subform's source object to that query.或者,如果您希望您的表单以特定查询打开并在打开时显示,您可以将子表单的源对象设置为该查询。 Using the properties window find the source object drop down and find the query you want to show when the form opens.使用属性窗口找到源对象下拉列表,然后找到要在表单打开时显示的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM