subform not refreshing

B

buzzmcduffie

When the user types in the main form and then goes into the subform to select
from a listbox item, eveything is fine - the key is correct. However, when
the user then goes to add another record in the main form, the previous
subform data appears. This just happens occasionally. If they save the 2nd
record, go back to the another record and then return to the 2nd record, the
subform data (from the 1st record) is gone. I have relinked the subform
several times with no success in stopping the errors.
Table appears to be right. Just a problem for the data entry folks.
Any suggestions?
 
R

Rick Brandt

When the user types in the main form and then goes into the subform to
select from a listbox item, eveything is fine - the key is correct.
However, when the user then goes to add another record in the main form,
the previous subform data appears. This just happens occasionally. If
they save the 2nd record, go back to the another record and then return
to the 2nd record, the subform data (from the 1st record) is gone. I
have relinked the subform several times with no success in stopping the
errors. Table appears to be right. Just a problem for the data entry
folks. Any suggestions?

Even though it should be totally automatic I have on a few occasions had
subforms do what you are describing. I just add a Requery of the subform
to the Current event of the main form and that has always cleared it up.
 
B

buzzmcduffie

Rick - can you be more specific for this? on the main form under ON CURRENT,
what would be my code?
 
R

Rick Brandt

Rick - can you be more specific for this? on the main form under ON
CURRENT, what would be my code?

In the On Current property box you choose [Event Procedure] from the list
of choices, then press the build [...] button to the right of the
property box.

Once in the VBA code editor the cursor will be positioned between two
lines that begin and end the code-block for the Current event. IN that
area you enter either...

Me.NameOfSubformControl.Requery
or
Me.NameOfSubformControl.Form.Requery

In most cases just requerying the subform control works for me (the first
example). If that doesn't work for you try the second variation.

Note that the syntax above requires that you replace
"NameOfSubformControl" with the name of your actual subform *control*
found on the main form and that the name of that control might not be the
same as the name of the form displayed within.

If you created the subform using the form wizard or with drag-and-drop,
then the control should be named the same as the form (unless that
control name was already in use).
 
B

buzzmcduffie

perfect! thanks!

Rick Brandt said:
Rick - can you be more specific for this? on the main form under ON
CURRENT, what would be my code?

In the On Current property box you choose [Event Procedure] from the list
of choices, then press the build [...] button to the right of the
property box.

Once in the VBA code editor the cursor will be positioned between two
lines that begin and end the code-block for the Current event. IN that
area you enter either...

Me.NameOfSubformControl.Requery
or
Me.NameOfSubformControl.Form.Requery

In most cases just requerying the subform control works for me (the first
example). If that doesn't work for you try the second variation.

Note that the syntax above requires that you replace
"NameOfSubformControl" with the name of your actual subform *control*
found on the main form and that the name of that control might not be the
same as the name of the form displayed within.

If you created the subform using the form wizard or with drag-and-drop,
then the control should be named the same as the form (unless that
control name was already in use).
 

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