首页 文章

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

提问于
浏览
1

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

组合框选择被评估为ID . 我需要把它作为文本 . 我发现了其他类似的问题,但无法让它发挥作用 . 任何人都可以带我走过吗?

我找到的最接近的线程是http://www.access-programmers.co.uk/...ad.php?t=58062,但不确定"joining to the lookup table"需要什么 .

在下面的代码中,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

    如果你想得到一个组合框的值(我不确定你的哪个 .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
    

相关问题