1

我在 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

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

4

1 回答 1

0

如果您想获取组合框的值(我不确定您.value的哪个是组合框,如果有的话),那么您可以编写如下内容:

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
于 2013-08-09T18:20:20.773 回答