Reflecting changes in a form to its subform

gellerche

Registered User.
Local time
Today, 07:24
Joined
Jun 19, 2001
Messages
73
I have a form which has a subform and buttons to move through the recordset displayed by the main form (First, Next, etc.). I tie the subform's data to the form's data by setting a public variable equal to an ID from the form, then the subform is filtered off of that public variable.

When I open the form or click the First, Next, etc. buttons (ie. go from record to record), the data in the form is correct. However, the only time the subform is correct is on the first record. After I click a button, the ID the subform looks for is 0, and it becomes blank. Is there a way, when I click a button, to force the subform to refresh?

I did add (in VBA) a Form_Load statement in the button's click action that reloads the subform when the button's clicked. This pulls up the subform with the correct data, but all by itself (separately from the form). What I could use is a way to refresh the subform, but within the form.

Thank you,


Steve Geller
 
Steve,

Forms![MainForm]![Subform].Requery

Just change MainForm and Subform to your names.

hth,
Wayne
 
Wayne:

Thank you. I added the code, but it's still not working right. Could you tell me under what event on the subform I have to put the filter information?

Thanks,

Steve Geller
 
Steve,

I'd make the data source for your subform a query based on
its table. In the criteria for your key field make it:

=Forms![frmMain]![YourKey]

Then in the OnCurrent or OnClick event of your main form
you can do the Forms![MainForm]![Subform].Requery

Wayne
 
Thank you to everyone for all your help. I had the master and child linked, and I was using the Forms![frmMain]![YourKey] syntax. What was causing the problem was that I had the Filter code (and code for populating a drop down box) in both the Load and Open event for the subform. When I moved the code into just the Open event, it worked fine. I don't know why it was a problem, but it's fixed.

Thank you all again,

Steve Geller
 

Users who are viewing this thread

Back
Top Bottom