Subquery where subform is shared between 2 forms (1 Viewer)

knn9413

Registered User.
Local time
Today, 00:23
Joined
Feb 18, 2015
Messages
36
There are 2 mainforms and both of them share a subform. This subform is an add subform and I want the mainform to be refreshed after the data entry.

Prior to the sharing, I had it coded it the way below and it works fine

Code:
Forms![B]frmMainformnoproc[/B]!frmActiveTasks.Requery

How would I recode this requery when it shared between 2 forms. frmMainformnoproc is the name of one of the main forms.

Thinking about this problem a little bit.
The code above was present after an update was completed in the subform. Maybe I should be doing it after I close the subform and refresh the mainform.

Based on that line of thinking I tried to add the code in the Activate event / Got Focus event of the mainform but the form did not get refreshed.

The code was obviously different as

Me!frmActiveTasks.Requery
 
Last edited:

knn9413

Registered User.
Local time
Today, 00:23
Joined
Feb 18, 2015
Messages
36
I have one additional doubt since my form activate / got focus event isn't work. I click on a command button to open up the subform. So when I close the subform, what event should be triggered first? I think I would need to put the requery in there...
 

Cronk

Registered User.
Local time
Today, 17:23
Joined
Jul 4, 2013
Messages
2,777
Probably the best event to use is the AfterInsert of the sub form.

The code would be
me.parent.requery

This way the sub form is re-querying the form in which the instance of the sub form is instanced.
 

RainLover

VIP From a land downunder
Local time
Today, 17:23
Joined
Jan 5, 2009
Messages
5,041
The is a list in Access that tells you the order in which Events happen.

Like Before Update happens before After Update. There are many others which can be confusing.
 

knn9413

Registered User.
Local time
Today, 00:23
Joined
Feb 18, 2015
Messages
36
Probably the best event to use is the AfterInsert of the sub form.

The code would be
me.parent.requery

This way the sub form is re-querying the form in which the instance of the sub form is instanced.

I had the different version of the me.parent as I mentioned in my post. Me.Parent is incorrect. The version I had was working as long as the subform was not shared between 2 forms. The problem is strictly because of the fact it is shared now and I don't want 2 forms with different names doing exactly the same job.
 

knn9413

Registered User.
Local time
Today, 00:23
Joined
Feb 18, 2015
Messages
36
The is a list in Access that tells you the order in which Events happen.

Like Before Update happens before After Update. There are many others which can be confusing.

I actually went through each event under the main form to plug in the requery and didn't see any of them firing. Currently I had to implement a button on the mainform which when clicked will refresh the subforms. I was really hoping to get away from that..
 

Cronk

Registered User.
Local time
Today, 17:23
Joined
Jul 4, 2013
Messages
2,777
You are not getting it. The two 'main' forms have separate sub form controls, one each. Just because it is the same form that is being used for the sub forms in both 'main' forms, they behave independently and linked to their respective parent forms. As I wrote before, it's a different instance of the form in each.

Was not your original request about requerying the parent form. "I want the mainform to be refreshed after the data entry (of the sub form)"

Then put the code I originally posted in the AfterInsert and the AfterUpdate events of the form acting as the sub form
viz Me.parent.requery
 

knn9413

Registered User.
Local time
Today, 00:23
Joined
Feb 18, 2015
Messages
36
You are not getting it. The two 'main' forms have separate sub form controls, one each. Just because it is the same form that is being used for the sub forms in both 'main' forms, they behave independently and linked to their respective parent forms. As I wrote before, it's a different instance of the form in each.

Was not your original request about requerying the parent form. "I want the mainform to be refreshed after the data entry (of the sub form)"

Then put the code I originally posted in the AfterInsert and the AfterUpdate events of the form acting as the sub form
viz Me.parent.requery

That didn't work..Maybe because the data is in a subform within the mainform? Or just because the record in the add form is getting added by clicking a button... unsure at this time
 

Cronk

Registered User.
Local time
Today, 17:23
Joined
Jul 4, 2013
Messages
2,777
What are the recordsources of the subform and the two 'main' forms? On what fields are they linked? What data field is not being updated in the 'main' forms?
 

RainLover

VIP From a land downunder
Local time
Today, 17:23
Joined
Jan 5, 2009
Messages
5,041
Are you wanting to simply Requery the Main form or=================

Do you want to change add some Data.
 

Cronk

Registered User.
Local time
Today, 17:23
Joined
Jul 4, 2013
Messages
2,777
RainLover

You do realise that this will reopen at the first record not the current record.

I know but for the benefit of the OP, depends how many records in the recordsource for the form eg OpenArgs, Filter could be restricting to one record. Alternatively, move to the particular record after the requery.
 

knn9413

Registered User.
Local time
Today, 00:23
Joined
Feb 18, 2015
Messages
36
RainLover



I know but for the benefit of the OP, depends how many records in the recordsource for the form eg OpenArgs, Filter could be restricting to one record. Alternatively, move to the particular record after the requery.

Here is the database that I am working on. Hopefully you should be able to understand looking at this. Once you open up the database, open up the login form. Use the password as "password" for any user.

  • You will see 2 forms. one for active and other for non active tasks
  • Click on Add task up on the top
  • It will open up a popup form and most of the entries there are self explanatory
  • Once you click on Add task, it is supposed to refresh the main form. ( I currently have the refresh button doing the job)
  • The problem I have is the "Active Task" subform that you see in the main form is used from another form as well (not included here)
  • I hence wanted a generalized way if possible without specifying the name of the main form

Once again, I really appreciate you taking the time in getting this resolved.
 

Attachments

  • Tasks_rework - orig.accdb
    896 KB · Views: 67

RainLover

VIP From a land downunder
Local time
Today, 17:23
Joined
Jan 5, 2009
Messages
5,041
You have a few problems.

Why do you want to write to the Main Form. It is unbound. Nothing will be saved.

Also try making the names of everything a little tidy so we can tell what is what.

Put tbl in front of Tables. qry for queries frm for forms etc.

Do you think you could find something a little bit more descriptive. What is a Command47. No one will know what that is about. Same with text29 or 37.

Please review your work.
 

Users who are viewing this thread

Top Bottom