Good practise to refresh combo box on subform?

L

Laurel

I have a combo box in a subform that is on a tabpage. It is filtered on
the value of a field in the parent form. The contents of the combo box
look good when I'm sitting on the first row of the parent form. But if I
move to other records, it keeps filtering based on the value in the first
row.

I hypothesise that I need to refresh it by hand, and so I tried putting the
following code in the change event of the tab control:

Contact_ID is the name of the combo box.

Private Sub TabFunders_Change()
Forms!frmFunderEntry!ctrlGrantsSub.frmGrantsSub!Contact_ID.Requery
End Sub

At runtime I get this error on the line of code above:

runtime error 438
Object doesn't support this object or method.

When I try execute the Requery method on a simple combo box from it's own
context (no subforms and stuff), .Requery seems to be OK. That is, I put
this line of code above the offending line... Me!cboFind.Requery. There's
no error there.

1 - Am I taking the right approach in general?
2 - What's wrong with the syntax I'm using to refresh the dropdown?
 
S

Steve Schapel

Laurel

I can't quite grasp the meaning of the code you have used, in particular
what ctrlGrantsSub and frmGrantsSub refer to, compared with your
generalised description. But anyway, first of all I would suggest the
Current event of the parent form would be a more applicable spot for
your code. Assuming frmGrantsSub is the name of the subform, and
Contact_ID is the name of the combobox, try...
Me.frmGrantsSub.Form!Contact_ID.Requery
 
L

Laurel

Thanks. That did the trick. What I was trying to do was name the subform
control and then the form that was within it. The syntax that actually
worked was:
Me.ctrlGrantsSub.Form!Contact_ID.Requery.

Your syntax used ".Form" to refer to the subform within the subform control.
I tried to use the subform name explicitly.

I may have contributed to the confusion by carefully renaming my subform
controls so they don't have the same name as the subform itself. A while
back I was having a terrible time selecting the control (as contrasted with
the form) so that I could supply linking field info. That's when I got in
this habit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top