无法使级联组合框工作 [英] Can't get the cascading combo boxes to work

查看:225
本文介绍了无法使级联组合框工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使级联组合框,但我似乎无法让它工作。例如,如果我在第一个组合框中选择特定的计算机,则第二个组合框应该只显示与该计算机兼容的HDD。我还提供了一个链接到我创建的数据库。



我有两个表格,其中包含以下字段:




  • tbl电脑(电脑)

  • tblHDD(HDD,电脑)



cboxComputer Row Source: SELECT tblHDD.HDD,tblHDD.Computer FROM tblHDD;

  Private Sub cboxComputer_AfterUpdate()
Me.cboxHDD.RowSource =SELECT HDD & _
FROM tblHDD& _
WHERE Computer =& Nz(Me.cboxComputer)& _
ORDER BY HDD
End Sub

https://drive.google.com/file/ d / 0Bye-M8FI1tRURmQ0MEFzRjBCdWM / view?usp = sharing

解决方案

数据库中的Computer字段是字符串数据类型。尝试在名称周围加上撇号,如下所示:

  Private Sub cboxComputer_AfterUpdate()
Me.cboxHDD.RowSource =SELECT HDD& _
FROM tblHDD& _
WHERE Computer ='& Nz(Me.cboxComputer)& '& _
ORDER BY HDD
End Sub


I am trying to make cascading combo boxes but I can't seem to get it to work. For example, if I select a specific computer in the first combo box, then the second combo box should only show the HDD that is compatible with that computer. I also provided a link to the database that I have created. Can anyone help me out with this?

I have 2 tables with the fields:

  • tblComputer(Computer)
  • tblHDD(HDD, Computer)

cboxComputer Row Source: SELECT tblComputer.Computer FROM tblComputer;

cboxHDD Row Source: SELECT tblHDD.HDD, tblHDD.Computer FROM tblHDD;

Private Sub cboxComputer_AfterUpdate()
    Me.cboxHDD.RowSource = "SELECT HDD " & _
                           "FROM tblHDD " & _
                           "WHERE Computer = " & Nz(Me.cboxComputer) & _
                           "ORDER BY HDD"
End Sub

https://drive.google.com/file/d/0Bye-M8FI1tRURmQ0MEFzRjBCdWM/view?usp=sharing

解决方案

The Computer field in the database is a string datatype. Try putting apostrophes around the name like this:

Private Sub cboxComputer_AfterUpdate()
    Me.cboxHDD.RowSource = "SELECT HDD " & _
                       "FROM tblHDD " & _
                       "WHERE Computer = '" & Nz(Me.cboxComputer) & "' " & _
                       "ORDER BY HDD"
End Sub

这篇关于无法使级联组合框工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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