Refresh vs RunCommand acCmdSaveRecord

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Refresh vs RunCommand acCmdSaveRecord

Post by Pat »

I have inherited this database that i have converted to link to SQL Server backend.
In this particular form there are numerous Refresh commands.
I notice this forces a Form_Current and Form_BeforeUpdate na Form_AfterUpdate.

I am now using the runcommand to write a record while in the AfterUpdate event of a control on the form, this produces a 2501 error the first time thru, but every other time thru on the same record it is fine, it doesn't bomb.

Is it better to use the runcommand if the form is dirty?

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Refresh vs RunCommand acCmdSaveRecord

Post by HansV »

Refresh and RunCommand acCmdSaveRecord save different purposes.

According to the Access 2003 help, "The Refresh method immediately updates the records in the underlying record source for a specified form or datasheet to reflect changes made to the data by you and other users in a multiuser environment." In other words, if someone else edited and saved a record since you loaded it, Refresh will update your view of it.

RunCommand acCmdSaveRecord will save your edits.

So you should not replace one with the other.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Refresh vs RunCommand acCmdSaveRecord

Post by Pat »

I'll go back a little, there's a combo box that allows the user to change status.
At the end of the After Update event of the combo box there was a refresh command, a couple of times thru this iteration produced an error where Access apologises before it crashes out. And the AfterUpdate event of the combo box completes before the access crash.

If i delete the Refresh command it all seems to work ok, it doesn't matter how many times i change status.
Strange indeed.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Refresh vs RunCommand acCmdSaveRecord

Post by HansV »

In that case, I'd omit the Refresh command. I wouldn't replace it with RunCommand acCmdSaveRecord.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Refresh vs RunCommand acCmdSaveRecord

Post by Pat »

Just to try to understand this, what do you think causes Access to crash out?

Obviously everytime is goes thru the Refresh command in the AfterUpdate event of the status change combo box it forces Access to go to the Form_BeforeUpdate and Form_AfterUpdate events.

I have taken it out, so i will see how this user testing goes.

Thank you for your time Hans.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Refresh vs RunCommand acCmdSaveRecord

Post by HansV »

I'm sorry, I don't know what causes Access to crash; it is probably a highly specific combination of factors.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Refresh vs RunCommand acCmdSaveRecord

Post by Pat »

Silly question really. Thanks for your time.

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Refresh vs RunCommand acCmdSaveRecord

Post by Pat »

As it turns out I replaced all
Me.Refresh
with
If Me.Dirty = True Then Me.Dirty = False
This forces a Form_Before and Form_AfterUpdate but NOT a Form_Current as the Me.Refresh.

This seems to have solved the problem.