update subform without updating main form

s_samira_21

Registered User.
Local time
Today, 19:11
Joined
Jun 8, 2011
Messages
52
Hellllllo everyone!

Another Problem with my Project in Access 2007!

I have a form named "Organization_Details" that contains a subform named "project_subform".
Also I have a command button named "btn_AddPro" that opens "Project_Details" form to add a new project.
The Problem is that when I add details of a new project and save that, the sub form don't show the new project and I must close "Organization_Details" form and reload it to see the new Project in the subform.

*** I made "project_subform" locked because I don't want allow the user to edit the information in subform. Also I need "btn_AddPro" because the subform don't show all details and to edit the record, user should go to "Project_Details" form.***
 
You could requery the subform when the main form gets the focus back to make it show the updated data, as in
Code:
subformname!sourceobject.requery
 
do you mean that i should write this code in form got focus?
i wrote this:

Private Sub Form_GotFocus()

Person_subform!SourceObject.Requery
Project_subform!SourceObject.Requery

End Sub

Because I have 2 subforms

But it doesn't work
 
Sounds right, give it a go and see what happens :)
 
According to Access Help a Form doesn't actually get focus unless it is devoid of any Controls that can receive focus.

When you want to trigger some action, when returning to a Form, you use the Form_Activate event.

Linq ;0)>
 
Oh yeah... that's what I meant... :)
 
thank you
but
what should i put instead of SourceObject?
I want hole subform to be updated
I used this:
Private Sub Form_Activate()

Task_subform.Requery
Person_subform.Requery
Project_subform.Requery

End Sub

but nothing occurred
 
It's the form in the subform control you're requerying, not the subform control itself. I think the code is
Code:
subformcontrol.form.requery
 
I am sure simply "subdetails.requery" should work, when subdetails is the name of the control of the subform.

maybe it's timing - what code are you using to
a) open the new project form and then
b) requery the subform.

you have to wait for the new project form to close, before requerying.
 
It's the form in the subform control you're requerying, not the subform control itself. I think the code is
Code:
subformcontrol.form.requery

I think James is right

As to when to run it, the easiest way is to open the detail form as a dialog and then put the code in after the docmd.openform line.
By opening as a dialog, code in the calling form pauses until the dialog closes and then the code resumes.

Putting a requery command on a subform's activate event could cause unwanted behaviour: It will requery at inopportune moments.
 
But I don't know what should I put Instead of "subformcontrol" when I want hole subform to be update.

Excuse me! I'm not good in VBA....
 
In the design of the main form, click on the edge of the subform (so the subform control is selected - not the form inside it). Check the control's properties and the Name of the control.
 
it doesn't work

Private Sub Form_Activate()
Task_subform.Form.Requery
Person_subform.Form.Requery
Project_subform.Form.Requery
End Sub

I'm cryiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing :((
 
Private Sub Form_Activate()
Task_subform.Form.Requery
Person_subform.Form.Requery
Project_subform.Form.Requery
End Sub

I'm cryiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing :((
Don't cry, you'll short out your keyboard... is the above producing an error?
 
Like I said, I'm sure Form_Activate is not the place to do it.

But even so, make a 'Refresh' button and put the code in its Click event. Then you can check whether the code works. Then you can think about what event(s) it needs to run under.

To be honest, I don't think it will be one of the main form's events at all.
I think you'd put it on the afterupdate event of the details form that would call a public sub on the main form.

For someone who doesn't know VBA you're trying to do some quite sophisticated things. Don't be disheartened if they don't work first attempt (or even tenth attempt). It's normal :)
 

Users who are viewing this thread

Back
Top Bottom