Cascading Combo Box Help (1 Viewer)

LaurieW

Registered User.
Local time
Today, 09:30
Joined
May 9, 2002
Messages
99
I have been trying to get this to work for days, have tried different examples from this forum and elsewhere and don't know what I am doing wrong.

I have one combo box for Module and another for Tool. I want the Tool combo box to only list the Tools for the Module selected in the first combo box. I'm attaching a test database. Can anyone see what I have done wrong? It must be something in the Module combo box AfterUpdate event, but I can't see it. Thanks for any help you can provide.
 

Attachments

  • CascadeHelp.accdb
    1.8 MB · Views: 57

Minty

AWF VIP
Local time
Today, 14:30
Joined
Jul 26, 2013
Messages
10,380
Your Code is resetting the rowsource to refer to a field call [ID] which doesn't exist in tblTool...

Code:
Private Sub cboModule_AfterUpdate()
With Me![cboTool]
    If IsNull(Me!cboModule) Then
      .RowSource = ""
    Else
      .RowSource = "SELECT [Tool] " & _
                   "FROM TblTools " & _
                   "WHERE [COLOR="Red"][ID][/COLOR]=" & Me.cboModule
    End If
    Call .Requery
  End With
End Sub

Try using ToolID instead. And you don't need to refer to the controls in the way you have try;

Code:
Private Sub cboModule_AfterUpdate()

    If IsNull(Me.cboModule) Then
           Me.cboTool.RowSource = ""
    Else
           Me.cboTool.RowSource = "SELECT [Tool] " & _
                   "FROM TblTools " & _
                   "WHERE [ToolID]=" & Me.cboModule
    End If
    Requery
  
End Sub
 

LaurieW

Registered User.
Local time
Today, 09:30
Joined
May 9, 2002
Messages
99
Thanks, I tried both of those and still doesn't work. I get this error:

"The record source 'SELECT [Tool] FROM tblTools WHERE [ToolID]=1' specified on this form or report does not exist."

I tried changing ToolID to ModuleID and same error.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:30
Joined
Aug 30, 2003
Messages
36,139
Double check the table name. ;)

And you want ModuleID.
 

Users who are viewing this thread

Top Bottom