组合框选择为字符串中的文本

时间:2013-08-09 14:47:06

标签: ms-access combobox access-vba

我在Access中有一个Form,它使用组合框列表中的选项来推动创建报告。

组合框选择被评估为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

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

1 个答案:

答案 0 :(得分: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
相关问题