刷新MS Access窗体/基于组合框的值查询组合、窗体、MS、Access

2023-09-08 10:58:23 作者:千山暮雪

pretty的简单的解释。我有一个列有10项,5项与2010年和2011 5项的表格。

Pretty simple explanation. I have a table with 10 entries, 5 entries with the year 2010 and 5 entries with 2011 in a column.

在查询我有,我用像* 2010来过滤掉所有条目等于2010和显示ONL这些记录。

In the query I have, I use Like *2010 to filter out all entries equal 2010 and display onl those records.

在我的表,我有组合框被填充每个特殊的一年(从不同的表)。所以我的组合框的值是2010和2011。

On my form, I have combobox being populated with each unique year (from a different table). So my combobox values are 2010 and 2011.

是否有可能,当我选择说2011,我修剪右4个字符,用我的标准一样,刷新和重新查询表,都在VBA做?

Is it possible, when I select say 2011, I trim the right 4 characters and use as my Like criteria to refresh and requery the form, all done within VBA?

推荐答案

您可以从引用控件的值在查询运行一个访问会话中,只要其中包含的控制是开放的形式。

You can refer to the value of a control in a query run from within an Access session, as long as the form which contains that control is open.

SELECT *
FROM YourTable
WHERE date_field_as_text Like "*" & Forms!YourForm!YourCombo;

因此​​,也许你可以使用一个类似的查询作为窗体的记录源,并做 Me.Requery 的组合框的更新事件之后。

So perhaps you can use a similar query as your form's record source, and do Me.Requery in the combo box's after update event.

如果这还不够接近你想要的东西,请给我们介绍一下有关字段的数据类型的详细信息。添加表数据,以你的问题还可以帮助简短的样本;请说清楚的日期字段是否文本或日期/时间。

If that's not close enough to what you want, please give us more information about the data types of the fields involved. Adding brief samples of the table data to your question could also help; please make it clear whether the "date" fields are text or Date/Time.