Access 2007参数查询中的下拉菜单 [英] Dropdown in Access 2007 parameter query

查看:260
本文介绍了Access 2007参数查询中的下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望访问参数查询向用户询问一个值(在这种情况下为位置).当我在条件"字段中键入[Enter location]时,它工作正常:我得到一个对话框(输入参数值),其中包含一个文本框和我的文本(输入位置).到目前为止,一切都很好.这行得通(结果也是如此).

I want a Access parameter query to ask an user for a value (a location in this case). When I type [Enter location] in the Criteria field it works fine: I get a dialog box (Enter Parameter Value) with a textbox and my text (Enter Location). So far, so good. This works (the result also).

但是现在我想要一个下拉列表/组合框(而不是textbox)供用户选择位置.我创建了一个表单,然后在条件"字段中键入Forms![Form1]![CmbLocation].

But now I want a dropdown/combobox (instead of a textbox ) for the user to pick a location. I made a form and type Forms![Form1]![CmbLocation] in the Criteria field.

像这样: http://office.microsoft.com/zh-我们/access/HA011170771033.aspx

但是我仍然得到一个文本框(引用为textlabel).

But I still get a textbox (with the reference as textlabel).

我做错了什么?有任何建议吗?

What am I doing wrong? Has anybody any advice?

推荐答案

除了Albert的建议之外,您可能还希望在查询本身中完成此工作,以便它是可引导的".为此,您必须编写函数,该函数返回在窗体的组合框中选择的值.会是这样的:

In addition to Albert's suggestion, you might want to make this work within the query itself, so that it's "bootstrappable." To do that, you'd have to write function that returns the value chosen in the combo box on the form. It would be something like this:

  Public Function ReturnMyCriterion() As Variant
    DoCmd.OpenForm "dlgGetCriterion", , , , , acDialog 
    With Forms!dlgGetCriterion
      If .Tag <> "Cancel" Then
         ReturnMyCriterion = Nz(!cmbMyCombo, "*")
      End If
    Else
      ReturnMyCriterion = "*"
    End With
    Close acForm, "dlgGetCriterion"
  End Function

(使用acDialog开关打开表单时,只要表单处于打开状态或可见状态,代码就会暂停;要从组合框中获取值,您必须将表单的.Visible属性设置为False.您可以在组合框的AfterUpdate事件中或在确定"按钮中执行此操作,您还需要一个取消"按钮,将表单的.Tag属性设置为取消",然后将表单的.Visible属性设置为False;这就是全部相对较标准的方法来处理Access中的对话框形式.

(when opening a form with the acDialog switch, the code pauses as long as the form is open or visible; to get the value out of the combo box, you have to set the form's .Visible property to False. You could do this in the AfterUpdate event of the combo box, or in the OK button. You'd also want a Cancel button that set's the form's .Tag property to "Cancel" and then sets the form's .Visible property to False; this is all relatively a standard approach to working with dialog forms in Access).

然后您将查询中的条件设为:

You'd then make the criterion in your query be:

  Like ReturnMyCriterion()

也就是说,假设您要在组合框中没有选择任何值的情况下返回所有记录.

That is, assuming you want to return all records if no value is chosen in the combo box.

这篇关于Access 2007参数查询中的下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆