use OnClick of combobox to refresh a subform

S

Sheryl

My form has an unbound combobox 'category', and a subform
based on a query which includes a field 'category'. The
query's Criteria field forces the subform to display only
records whose category matches the value in the combox.

I am trying to write an OnClick subroutine for the combo
box so that changing the category refreshes the subform.
But I don't seem to identify the subform properly, and the
program aborts with an error. The form is 'frmRunId', the
combo box is 'CategoryBox', the subform is 'sfrmParms',
and the query is 'qryParms'. What is the correct syntax?

I have tried the following (in CategoryBox_Click); program
aborts on 2nd line:

Dim parms as Control
Set parms = Forms!sfrmParms
parms.Refresh
 
D

Dirk Goldgar

Sheryl said:
My form has an unbound combobox 'category', and a subform
based on a query which includes a field 'category'. The
query's Criteria field forces the subform to display only
records whose category matches the value in the combox.

I am trying to write an OnClick subroutine for the combo
box so that changing the category refreshes the subform.
But I don't seem to identify the subform properly, and the
program aborts with an error. The form is 'frmRunId', the
combo box is 'CategoryBox', the subform is 'sfrmParms',
and the query is 'qryParms'. What is the correct syntax?

I have tried the following (in CategoryBox_Click); program
aborts on 2nd line:

Dim parms as Control
Set parms = Forms!sfrmParms
parms.Refresh

You have to work through the subform control on the main form, because
the subform itself isn't a member of the Forms collection. Also, it
would be the Requery method you'd call, not Refresh. Now, the subform
control that displays the form object named "sfrmParms" may or may not
also be named "sfrmParms". If it is, you could could write code like
this:

Private Sub CategryBox_Click()

Me!sfrmParms.Requery

End Sub

If the subform control isn't named the same as the form, you must
substitute the name of the control in the above code.
 
D

Dirk Goldgar

Sheryl said:
My form has an unbound combobox 'category', and a subform
based on a query which includes a field 'category'. The
query's Criteria field forces the subform to display only
records whose category matches the value in the combox.

I am trying to write an OnClick subroutine for the combo
box so that changing the category refreshes the subform.
But I don't seem to identify the subform properly, and the
program aborts with an error. The form is 'frmRunId', the
combo box is 'CategoryBox', the subform is 'sfrmParms',
and the query is 'qryParms'. What is the correct syntax?

I have tried the following (in CategoryBox_Click); program
aborts on 2nd line:

Dim parms as Control
Set parms = Forms!sfrmParms
parms.Refresh

You have to work through the subform control on the main form, because
the subform itself isn't a member of the Forms collection. Also, it
would be the Requery method you'd call, not Refresh. Now, the subform
control that displays the form object named "sfrmParms" may or may not
also be named "sfrmParms". If it is, you could could write code like
this:

Private Sub CategryBox_Click()

Me!sfrmParms.Requery

End Sub

If the subform control isn't named the same as the form, you must
substitute the name of the control in the above code.
 
L

Larry Daugherty

You might look at http://www.mvps.org/access/forms/frm0031.htm "Referring to
form and subform controls ..." by Keri Hardwick. While you're there, look
poke around the site. It is probably the most useful site on the planet for
things Access.

Also, it would seem a natural to requery the subform from the AfterUpdate
event of the combobox.

HTH
 
L

Larry Daugherty

You might look at http://www.mvps.org/access/forms/frm0031.htm "Referring to
form and subform controls ..." by Keri Hardwick. While you're there, look
poke around the site. It is probably the most useful site on the planet for
things Access.

Also, it would seem a natural to requery the subform from the AfterUpdate
event of the combobox.

HTH
 

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