Can't get the cascading combo boxes to work

2019-03-06 09:14发布

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

1条回答
做自己的国王
2楼-- · 2019-03-06 10:16

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
查看更多
登录 后发表回答