View Full Version : Update Main Form from a Subform


DSimpson
05-02-2001, 10:38 AM
I am trying to requery a textbox on the main form by clicking in a checkbox control on a subform. The textbox counts the number of records on the subform that have the checkbox checked. I have it working by clicking a command button on the main form but I would like the requery to run every time a check one of the checkboxes.

charityg
05-02-2001, 10:57 AM
can't you just put the same code in the onclick event of the check box?

DSimpson
05-02-2001, 11:28 AM
No, because the commandbox is based on a macro using the Requery command and it gave me an error when I tried to use it in the subform. I tried using the requery method in VB but it isn't giving the correct data (i.e. it doesn't update when the first checkbox is checked and when all boxes are unchecked it still thinks one is checked). Can someone there show me an example of code that may work?

charityg
05-02-2001, 01:33 PM
try the afterupdate event of the checkbox

Rich
05-02-2001, 01:55 PM
Does F9 produce the results you require?

DSimpson
05-03-2001, 07:22 AM
Placing the requery code in the AfterUpdate event did NOT work, but using F9 does give the right results. However, I am trying to avoid an extra keystroke or click (i.e. I am trying to make the requery happen when the checkbox is clicked). I need to clarify the AfterUpdate event. It is working with one exception - it is always off by one. The first check does not change the count and the first uncheck does not change the count.

[This message has been edited by DSimpson (edited 05-03-2001).]

KevinM
05-03-2001, 07:47 AM
ChkBox AfterUpdate Event

Forms!MainFormName!SubFormName.Refresh
Forms!MainFormName!TextBoxName.Requery

HTH

DSimpson
05-03-2001, 10:49 AM
This works. Thanks for your help.

Rich
05-03-2001, 01:08 PM
ChkBox AfterUpdate Event
Me.Refresh
is all you need.