requery not working

J

jlute

I've placed a button on a tab control to requery the subform in the
tab:

Private Sub cmdrefreshassocs_Click()
On Error GoTo Err_cmdrefreshassocs_Click

Me.sfrmPKProfilesAssociations.Requery

Exit_cmdrefreshassocs_Click:
Exit Sub

Err_cmdrefreshassocs_Click:
MsgBox Err.Description
Resume Exit_cmdrefreshassocs_Click

End Sub

The subform is used in multiple main forms therefore it can be open
multiple times simultaneously. Here's what's going on:

The subform queries records in the main form's underlying table. With
the subform open in main forms "A" and "B" I will create a record in
"A" then go to form "B" and click the requery button. It will do
what's expected HOWEVER when I go back to form "A" and repeat these
steps the button will NOT requery the subform.

I've tried this several times and the button will only requery the
subform ONCE.

Does this make sense? It seems that I can only consistently requery
the subform from the Records > Refresh tool bar function.

Any help you have is greatly appreciated - thanks!
 
D

Douglas J. Steele

Are you sure that the name of the subform control is
sfrmPKProfilesAssociations? Depending on how you added the form as a
subform, the name of the subform control may be different than the name of
the form being used as a subform. It's the name of the subform control you
need to use.

You might also try:

Me!NameOfSubformControl.Form.Requery
 
J

jlute

Thanks, Doug.
Are you sure that the name of the subform control is sfrmPKProfilesAssociations?

Just double-checked that. That would be a big 10-4.
You might also try:

Me!NameOfSubformControl.Form.Requery

Gave that a shot but got the same results. The only way I've found to
requery the subform is to place my cursor in one of its controls and
use Records > Refresh from the menu bar.

My guess is that having the subform open multiple times is causing the
issue...?
 
D

Douglas J. Steele

My guess is that having the subform open multiple times is causing the
issue...?

Are you really talking about a subform? I don't understand how you can have
a subform open multiple times, since it doesn't have existance other than as
part of its parent form. From the Help file: "A subform is a form within a
form. The primary form is called the main form, and the form within the form
is called the subform. A form/subform combination is often referred to as a
hierarchical form, a master/detail form, or a parent/child form."
 
J

jlute

Are you really talking about a subform? I don't understand how you can have
a subform open multiple times, since it doesn't have existance other than as
part of its parent form. From the Help file: "A subform is a form within a
form. The primary form is called the main form, and the form within the form
is called the subform. A form/subform combination is often referred to as a
hierarchical form, a master/detail form, or a parent/child form."

I suppose I've broken some Access "laws". Let me explain this way
(using dummy names):

"FormA" is for Apple data. Its underlying table is tblProfiles and PK
is ProfileID. This form uses sfrmAssociations to relate Apple ID's to
other ID's from tblProfiles.

"FormB" is for Butter data. Its underlying table is also tblProfiles.
This form also uses sfrmAssociations to relate Butter ID's to other
ID's from tblProfiles.

Therefore, having FormA and FormB open simultaneously also opens
sfrmAssociations twice.
 
D

Douglas J. Steele

I suppose I've broken some Access "laws". Let me explain this way
(using dummy names):

"FormA" is for Apple data. Its underlying table is tblProfiles and PK
is ProfileID. This form uses sfrmAssociations to relate Apple ID's to
other ID's from tblProfiles.

"FormB" is for Butter data. Its underlying table is also tblProfiles.
This form also uses sfrmAssociations to relate Butter ID's to other
ID's from tblProfiles.

Therefore, having FormA and FormB open simultaneously also opens
sfrmAssociations twice.

Nothing wrong with that, and it's not relevant to your problem. As I believe
I indicated earlier, as far as Access is concerned, sfrmAssociations isn't
even open: only the parent form gets added to the Forms collection. And
since you need to refer to the subform via the subform control on the parent
form, there's no ambiguity.
 
J

jlute

Nothing wrong with that, and it's not relevant to your problem. As I believe
I indicated earlier, as far as Access is concerned, sfrmAssociations isn't
even open: only the parent form gets added to the Forms collection. And
since you need to refer to the subform via the subform control on the parent
form, there's no ambiguity.

Thanks, Doug. Looks like I'll need to keep poking at this!
sfrmAssociations is in Datasheet view. Maybe that has something to do
with it...? I've tried the button directly on it while in Single Form
view and it works fine. Unfortunately, theis view is not good for this
particular application.

Maybe the subform needs Refreshed rather than Requeried? Isn't there a
difference?
 
J

jlute

Ok. I went with Refresh:

Me!sfrmPKProfilesAssociations.Form.Refresh

This is working properly however I did a little research of the forum
and found several "warnings" about Refresh creating errors. That puts
me off a bit.

What to do...? I guess I'll try it for awhile and see!

Thanks for your help!
 

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