Update and Save Main form from another form (1 Viewer)

Gismo

Registered User.
Local time
Today, 08:47
Joined
Jun 12, 2017
Messages
1,085
Hi all,

I have a form "A" open
I then open form "B"

From form "B" I update form "A"

I want to save form "A" and refresh form "A"

Please advise correct code
Having issues with Save "DAW Sheet Main" from Form "B"

DoCmd.Close , "Import Material"
DoCmd.Save , "[DAW Sheet - Main]"
Forms![DAW Sheet - Main]![Material].Form.Requery
Forms![DAW Sheet - Main]![SavePlanning].Form.Requery
 
Last edited:

Ranman256

Well-known member
Local time
Today, 01:47
Joined
Apr 9, 2015
Messages
4,102
do you want to save data or requery?

1 saving data is automatic. Use can leave the record or the form and data saves.
also the command: DoCmd.RunCommand (acCmdSaveRecord) will save the record.

2. if this code is in '"Import Material"' form, it wont run since the form got closed ,thus no code to run.
 

Gismo

Registered User.
Local time
Today, 08:47
Joined
Jun 12, 2017
Messages
1,085
do you want to save data or requery?

1 saving data is automatic. Use can leave the record or the form and data saves.
also the command: DoCmd.RunCommand (acCmdSaveRecord) will save the record.

2. if this code is in '"Import Material"' form, it wont run since the form got closed ,thus no code to run.
I run an update query from form "B"
So I want to save the update in form "A"
then refresh subform within form "A"

The subform in form "A" is only visible when all the criteria in the form "A" is met
It seems like after the update query, when I go back to form "A" the subform is not visible
Only when I press F5 the subform on form "A: becomes visible

So I recon after the update query has run, the form Material subform did not save therefore the saveplanning will not be visible

DoCmd.Close , ""
DoCmd.Save , ""
Forms![DAW Sheet - Main]![Material].Form.Requery
Forms![DAW Sheet - Main]![SavePlanning].Form.Requery
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:47
Joined
Feb 19, 2002
Messages
36,296
Running an update query that affects records in the same or a different open form needs to be done with care.
1. when Form A opens Form B, it must first save its current record. It MUST NOT be left dirty.
Code:
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm ....
2. To requery FormA from form B
Code:
Forms!FormA.Form.Requery

PS. DoCmd.Save does NOT save the current record. It saves the form's design changes. Luckily, Access always saves dirty data when the form closes. So, you never noticed that the DoCmd.Save wasn't doing what you thought it was doing.
 

Gismo

Registered User.
Local time
Today, 08:47
Joined
Jun 12, 2017
Messages
1,085
Running an update query that affects records in the same or a different open form needs to be done with care.
1. when Form A opens Form B, it must first save its current record. It MUST NOT be left dirty.
Code:
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm ....
2. To requery FormA from form B
Code:
Forms!FormA.Form.Requery

PS. DoCmd.Save does NOT save the current record. It saves the form's design changes. Luckily, Access always saves dirty data when the form closes. So, you never noticed that the DoCmd.Save wasn't doing what you thought it was doing.
Thank you

By refreshing the main form and not the sub forms worked perfect
 

Users who are viewing this thread

Top Bottom