Application.Echo

Snowflake68

Registered User.
Local time
Today, 17:19
Joined
May 28, 2014
Messages
464
I am using Application.Echo to turn screen updating off whilst running a delete query on a datasheet subform. I switch the screenupdating back on again after the delete query has ran but the issue I have is when I use the Application.echo False it stops the recordcount displaying on the datasheet after I requery the datasheet.

I know it is the Application.Echo code that is causing the issue because if I comment it out and the run the code then the recordcount displays OK.

I want to use turn the screenupdating off otherwise you temporarily see all the records saying deleted until the requery runs.

Is this a bug in Access? How can I overcome it.

If i manually selecting the form and then press F5 the recordcount is displayed so I added the vba code to set the focus on the form and then refresh it but that doesnt have the same affect as pressing F5.

Code:
Private Sub cmdREMOVE_Click()

On Error GoTo ErrorHandling

Application.Echo False

DoCmd.SetWarnings False

    DoCmd.OpenQuery "2cc_ResetItemAdded"
    DoCmd.OpenQuery "2c_Delete_SelectionPreviewItem"
    
    DoCmd.RunMacro "ResetGrandTotals"
  
    Me.frmPreviewSelectionDatasheet.Requery
           
    Me!frmPreviewSelectionDatasheet.SetFocus
    
    Me.Refresh ' this line makes no difference but if I press F5 then it displays the recordcount

DoCmd.SetWarnings True

Application.Echo True

ErrorHandling:
Application.Echo True
    Exit Sub
    
End Sub

:banghead::banghead::banghead::banghead:
 
After Application.Echo True, add
Me.Recalc
 
After Application.Echo True, add
Me.Recalc

You are a genius this is perfect and works like a dream. Thank you so much. I have spent all morning on this and you sorted it so quickly.

;)
 
Yes tyou got it. Recalc only recalculate all controls on the form but does not bring new record as with requery
 
You have a strange mix of code and macro's going on there.
What does the macro do that you can't achieve in code?

Also instead of using
Code:
DoCmd.SetWarnings False
DoCmd.OpenQuery "2cc_ResetItemAdded"
DoCmd.OpenQuery "2c_Delete_SelectionPreviewItem"
DoCmd.SetWarnings True

You can use
Code:
CurrentDb.Execute "2cc_ResetItemAdded", dbFailOnError
CurrentDb.Execute "2c_Delete_SelectionPreviewItem", dbFailOnError

Which won't give the prompt about "updating x records". And therefore saves you turning the warnings off, which can sometimes hide other error messages that a user should see..
 
You have a strange mix of code and macro's going on there.
What does the macro do that you can't achieve in code?

Also instead of using
Code:
DoCmd.SetWarnings False
DoCmd.OpenQuery "2cc_ResetItemAdded"
DoCmd.OpenQuery "2c_Delete_SelectionPreviewItem"
DoCmd.SetWarnings True

You can use
Code:
CurrentDb.Execute "2cc_ResetItemAdded", dbFailOnError
CurrentDb.Execute "2c_Delete_SelectionPreviewItem", dbFailOnError

Which won't give the prompt about "updating x records". And therefore saves you turning the warnings off, which can sometimes hide other error messages that a user should see..

The macro is historic before I started writing in VBA so I should change this really as it only runs 4 queries.I am trying to write everything in VBA now but I have so much historic stuff to get through and time is always limited.

Ive not seen the CurrentDb.Execute before so definitely something I am going to try out. Many thanks

:)
 

Users who are viewing this thread

Back
Top Bottom