【问题标题】:Combo box selection as text in string组合框选择为字符串中的文本
【发布时间】:2013-08-09 14:47:05
【问题描述】:

我在 Access 中有一个表单,它使用组合框列表中的选择来驱动报表的创建。

组合框选择被评估为一个 ID。我需要将其作为文本获取。我发现了其他类似的问题,但无法使其正常工作。谁能帮我看看?

我找到的最近的线程是http://www.access-programmers.co.uk/...ad.php?t=58062,但不确定“加入查找表”意味着什么。

在下面的代码中,txtExpr1001、txtIndustry 和 txtSkill 是组合框。

代码:

Private Sub cmdSubmit_Click()

Dim sWhereClause As String

sWhereClause = "Expr1001 = '" & txtExpr1001.Value & "' AND MonthsCon >= " & txtMonth1.Value & " AND IndustryName = '" & txtIndustryName.Value & "' AND MonthsNonCon >= " & txtMonth2.Value & " AND Skill = '" & txtSkill.Value & "' AND MonthsSkills >= " & txtMonth3.Value & ""

Call DoCmd.OpenReport("IndustryCon + IndustryNonCon + Skills", acViewPreview, , sWhereClause)

End Sub

我的代码不会触发错误。报告打开,但它是空白的。

【问题讨论】:

  • 报告被拉起,但它是空白的。如果我查看具有完全相同标准的查询,它确实有结果。我很肯定问题是下拉选择被报告读取为数字。在得出这个结论之前,我确实将 sWhereClause 解构为更小的部分,并尝试了不同的报告。
  • 我还设法通过使用'Combobox.text'并将焦点(combobox.setfocus)设置为它之前将3个组合框之一读取为实际文本,但问题在于这是我不能同时将焦点集中到所有 3 个。
  • 谢谢!我将如何在我的 sWhereClause 中使用它?
  • 对文件共享网站有什么建议吗?谢谢!
  • 如果您尝试从组合框中获取值,则需要使用 column_box.column(0).value 或我认为您引用的任何列。

标签: ms-access combobox vba


【解决方案1】:

如果您想获取组合框的值(我不确定您的哪个.values 是组合框,如果有的话),那么您可以这样写:

Private Sub cmdSubmit_Click()

    Dim sWhereClause As String

    'Me.Combo_BoxName.Column(0) is going to be how you call the combo box
    'I put it right at the front of the string and chose ID as a random name as well

    sWhereClause = "ID = '" Me.Combo_BoxName.Column(0) & "' AND Expr1001 = '" & txtExpr1001.Value & "' AND MonthsCon >= " & txtMonth1.Value & " AND IndustryName = '" & txtIndustryName.Value & "' AND MonthsNonCon >= " & txtMonth2.Value & " AND Skill = '" & txtSkill.Value & "' AND MonthsSkills >= " & txtMonth3.Value & ""

    Call DoCmd.OpenReport("IndustryCon + IndustryNonCon + Skills", acViewPreview, , sWhereClause)

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多