Cascading ComboBox Subform Error.

Lister

Z Shift
Local time
Today, 20:01
Joined
Aug 24, 2003
Messages
305
Cascading ComboBox Subform Error.

Right I am stuck, and I hope someone out there can help.
I have a main form and a sub form. The subform is a form.

On this sub form, when I put the form together before linking/inserting onto the main form, I set up your classic Cascading Combo Box, select the Branch in the first Box and the lower combo box lists all the persons whom work there. Click Select No Problems at all.

Now when I linked/inserted this form into the main for as the subform and run the Main form. Everything works just as it should, EXCEPT I GET AN ERROR AND THE LOWER COMBO FAILS.

Thinking that it was my code I mucked around and around but got nowhere.

I knocked up a sample to see if it was me or something else and it’s got the same problem.

I have posted a screen shot of the error that I am getting.

I just don’t understand it works fine if you enter the correct value into the input box, and it works fine if you view just the subform, but as a subform, it falls over.

I am thinking that it’s the…

Code:
Private Sub cboBatch_AfterUpdate()
On Error GoTo Err_ErrorHandler

Me.Combo32.Requery

Exit_ErrorHandler:
Exit Sub

Err_ErrorHandler:
    MsgBox Err.Discription, vbExclamation, "Error #" & Err.Number
    Resume Exit_ErrorHandler


End Sub

The SQL for the first box is...

Code:
SELECT [tblParent].[ParentId], [tblParent].[Partent] 
FROM tblParent ORDER BY [tblParent].[Partent];

And the second..

Code:
SELECT [tblChild].[ChildID], [tblChild].[Child], [tblChild].[ParentID] 
FROM tblChild 
WHERE [tblChild].[ParentID]=[Forms]![frmExample]![cboParent] ORDER BY [tblChild].[Child];

But I’m quite at a loss. I have the awful feeling that its going to be something stupidly simple.
If anyone could help out that would be great.

Thanks
 

Attachments

  • CascadingComboboxProblem.gif
    CascadingComboboxProblem.gif
    9.2 KB · Views: 165
  • ProblemCascadingSubform.zip
    ProblemCascadingSubform.zip
    17.4 KB · Views: 148
Last edited:
Hi Lister,

The following works, but Mile posted the "proper" syntax in his FAQ on
how to reference subform objects.

Code:
SELECT [tblChild].[ChildID], 
       [tblChild].[Child], 
       [tblChild].[ParentID] 
FROM   tblChild 
WHERE  [tblChild].[ParentID] = [Forms]![frmWithTheProblem]![frmExample]!cboParent 
ORDER BY [tblChild].[Child];

Wayne
 
You need to refer specifically to the subform control on your mainform in your sql ie =[forms]![frmexample]![Mainchildsub].[Form]![cboParent]. Mainchildsub is the name of the control on your mainform.

Sometimes you can get away without the .[Form] bit as well.
 
Idiot <=

Knew it would be something simple :rolleyes:

Thanks Wayne and Hitch for seeing the forest where I only saw tree's :)

Larger on me if you are ever down this way.

Thanks
 

Users who are viewing this thread

Back
Top Bottom