refresh main form (1 Viewer)

scottappleford

Registered User.
Local time
Today, 06:11
Joined
Dec 10, 2002
Messages
134
Hi

I have a sub form and a button on the main form that needs to be pressed to refresh the data in the main form after data has been entered into the sub form.

Is it possible to have the main form refresh on exit from the sub form field automatically without having to press the button??

Could i hide the button and run a bit of code that runs the refresh button on the main form on exit from the subform field?

thanks in advance
 

MarkK

bit cruncher
Local time
Yesterday, 22:11
Joined
Mar 17, 2004
Messages
8,187
I assume you only need to update the main form if data in a subform field has changed. In this case, look into the AfterUpdate event for the indicated controls on the subform. From there you can run the Button_Click event handler on the parent form.
 

scottappleford

Registered User.
Local time
Today, 06:11
Joined
Dec 10, 2002
Messages
134
More clarification

Thanks

However I am new to db - what will the code look like?

thanks again
 

scottappleford

Registered User.
Local time
Today, 06:11
Joined
Dec 10, 2002
Messages
134
could you explain this in more detail

hi

thanks for helping with my question but being new to db - i need this explained in detail.

many thanks

scott
 

MarkK

bit cruncher
Local time
Yesterday, 22:11
Joined
Mar 17, 2004
Messages
8,187
Scott,
Can you ask more specific questions? The scope of what you're asking is significant, and I'm hesitant to spend time describing something that isn't what you need to know.
Do you know how to put buttons on forms? Do you know how to run code in reponse to a button click? What code do you have now that isn't working? What have you tried that has failed?
Cheers man,
Mark
 

godofhell

Database Guru
Local time
Yesterday, 22:11
Joined
May 20, 2005
Messages
180
Look at the event currently running on the onclick event of the button that refreshes the data on the main form, then copy it. Select a field on your form that you want to use it as a trigger for an AfterUpdate event, select properties, Events, select AfterUpate, then click on Event Procedure, paste the code you copied from the main form's button and paste it here. That should do the trick. You can also add the following line to any control on the main form or subform to force a refresh.
Docmd.Runcommand.accmdrefresh
 

scottappleford

Registered User.
Local time
Today, 06:11
Joined
Dec 10, 2002
Messages
134
refresh main form data after update from subform

Apologies for asking this question again.

I want to refresh the data on the main form to refrsh the calculations after updating a field on my subform. I am using the following code in the afterupdate event:

Docmd.Runcommand.accmdrefresh

however when i enter data into the field and tab out of it the data on the main form does not refresh. i currently have a refresh data button on the main form but wish to lose this in favour of the action happening automatically.

Thanks

scott
 

godofhell

Database Guru
Local time
Yesterday, 22:11
Joined
May 20, 2005
Messages
180
Why don't you simply move the focus to the main form, refresh it, then move the focus back to the subform.

Sub myTextbox AfterUpdate()
Form!MasterForm.setfocus
Docmd.Runcommand.accmdrefresh
Form!MasterForm!SubForm.SetFocus
End Sub
 

scottappleford

Registered User.
Local time
Today, 06:11
Joined
Dec 10, 2002
Messages
134
thanks

thanks for your help.

got it working fine now.

i do appreciate your input

thanks

scott
 

C.F.

Registered User.
Local time
Today, 01:11
Joined
Jan 7, 2009
Messages
17
I entered my database's version of this same code as follows:

Private Sub Text140_AfterUpdate()
'After Update of textbox
'move the focus to the main form,
'refresh it, then move the focus
'back to the subform.
Form![Frm Testy for Cond Too w Tabs frm].SetFocus
DoCmd.RunCommand.acCmdRefresh
Form![Frm Testy for Cond Too w Tabs frm]!ACQ_FY08.SetFocus
End Sub

but I'm getting the "Microsoft Visual Basic error message - Compile error : Argument not optional" with a yellow highlight and pointer to the first line "Private SubText140_AfterUpdate ()".

This seems so straight forward to me (a novice). Any suggestions for clearing this error?
 

JANR

Registered User.
Local time
Today, 07:11
Joined
Jan 21, 2009
Messages
1,623
Form![Frm Testy for Cond Too w Tabs frm].SetFocus

I belive it's :

Code:
Form[COLOR=red]s[/COLOR]![Frm Testy for Cond Too w Tabs frm].SetFocus

But woulden't this be easier:

Code:
Private Sub Text140_AfterUpdate()
Me!Parent.Refresh
End Sub

That way you will still have the focus in the subform, woulden't you?

What is the purpose of this refresh, if it just to update some calculated controls then perhaps this is better:

Code:
Private Sub Text140_AfterUpdate()
Me!Parent.Recalc
End Sub

JR
 

C.F.

Registered User.
Local time
Today, 01:11
Joined
Jan 7, 2009
Messages
17
JR - Thanks a million!

I took your excellent 3rd suggestion one step further for simplicity and just recalulated; then moved the focus to the next field. the code THAT WORKS looks like this:

Private Sub Text140_AfterUpdate()
'After Update of textbox
'recalculate the entire form
'move focus to the next field
Me.Recalc
Me.[Date Condition Resolved].SetFocus
End Sub

Thanks again for resolving clearing the error that was holding up our progress!
 

Users who are viewing this thread

Top Bottom