Solved

application echo

Posted on 1998-11-02
14
665 Views
Last Modified: 2013-11-18
i cant seem to get the requery method to respect "application.echo false" . i am trying to requery the records, and then come back to the current record without the screen updating until this is completed. everything else in my code up until requery respects the echo off. but the requery flashes back to the first record even though the echo is off. i have found the same problem with the findrecord method. what can i do?
0
Comment
Question by:rolo
  • 7
  • 3
  • 2
  • +2
14 Comments
 

Author Comment

by:rolo
Comment Utility
Edited text of question
0
 
LVL 5

Expert Comment

by:kulikuli
Comment Utility
Use an API call that turns off your applications' screen updating. It is very easy to use. I forgot it's name, but you can look it up in your win32API.txt
0
 
LVL 1

Expert Comment

by:mcmonniesa
Comment Utility
Because requery tell Access to go get the record set again, it will naturally go to the first record in the requeried record set.  If you haven't added a record prior to your current record, you could capture the record offset and use it with the "DoCmd.GotoRecord" command using the offset to goto the record you wanted.
0
 

Author Comment

by:rolo
Comment Utility
i cant imagine you read the text of my question
0
 
LVL 3

Expert Comment

by:tcurtin
Comment Utility
set a bkmk variable then return to it.
dim bkmk as string
bkmk = me.bookmark
application.echo false
me.requery
me.bookmark = bkmk
application.echo true
0
 

Author Comment

by:rolo
Comment Utility
it seems nobody understands my question. i am requerying and returning to the current record. I KNOW HOW TO DO THIS. I KNOW HOW TO BOOKMARK. I KNOW HOW TO REQUERY. I KNOW HOW TO TURN THE ECHO OFF. Like I stated pretty clearly in my question the requery method does not respect "application.echo false". it will still blink to the first record before returning to the current. please dont try to answer me without either trying it first, or just being aware of this. it seems like "kulikuli" has a point with that API. i cant seem to find which one it is. if someone can be more specific i would appreciate it.
0
 
LVL 2

Expert Comment

by:bclark100898
Comment Utility
This code works for me.  I tested it without the application.echo false command, and yes, you get a quick flash of the first record.  However, with the line as it appears below, the screen does a really quick blink, but it does not show any of the data from the first record.


Public Function FormRequery()
   
    ' requery sets focus back to the first record on the screen
    ' put the focus back where it was
       
    Dim CurrentRecord As String
    Dim jj As String
    Dim ControlSelStart As Integer
    Dim ControlSelLength As Integer
   
    jj = Me.ActiveControl.Name
    ControlSelStart = Me(jj).SelStart
    ControlSelLength = Me(jj).SelLength
   
    Application.Echo False
   
    If Me.NewRecord Then
       
        Me.Requery
        DoCmd.GoToRecord acForm, Me.Name, acNewRec

    Else
       
        CurrentRecord = Me.Bookmark
        Me.Requery
        Me.Bookmark = CurrentRecord
   
    End If
       
    Me(jj).SetFocus                                    ' Restore focus, requery puts focus on first control
    Me(jj).SelStart = ControlSelStart                  ' Restore selection, setfocus selects the entire text
    Me(jj).SelLength = ControlSelLength
       
    Application.Echo True
       
End Function


0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:rolo
Comment Utility

to bclark
if i set a bookmark and then requery it works as long as echo is on. when i set application.echo false going back to a bookmark generates this error "not a valid bookmark". ive tested this extensively with the echo false, with hide, with minimize. it will not be a valid bookmark in any of these states.
i have developed a reference to the current record and i do a findrecord. i have no problem with that. its just this flashing to the first record and then back, is getting me sick. help
0
 

Author Comment

by:rolo
Comment Utility
Adjusted points to 100
0
 
LVL 2

Expert Comment

by:bclark100898
Comment Utility
The only thing I can think of, and it is not much, is that the code I gave you has always been run from a hot key or a menu command, but never a command button.  If activeated by a button the line "ControlSelStart = Me(jj).SelStart" fails because in that case the active control is the button, and not a text field.  I don't think this has anything to do with the problem you describe.  Nevertheless, here is the code in its simplest form.  If I take out the application.echo, the first record flashes, if I put it back in, the first record does not flash.  If this still does not work, you might show us code that works, and code that fails, but in anycase, there must be something else going on (I used this code in Access 95 and 97, in Data Sheet, Single Form, and Continuous Forms views). Good Luck.

Public Function FormRequery()
   
    Dim CurrentRecord As String
    Dim jj As String
   
    Application.Echo False
   
    If Me.NewRecord Then
       
        Me.Requery
        DoCmd.GoToRecord acForm, Me.Name, acNewRec

    Else
       
        CurrentRecord = Me.Bookmark
        Me.Requery
        Me.Bookmark = CurrentRecord
   
    End If
       
    Application.Echo True
       
End Function
0
 

Author Comment

by:rolo
Comment Utility
to bclark

im testing it even simpler

Private Sub Command10_Click()
Dim bk As String
bk = Me.Bookmark
Application.Echo False
Me.Requery
Me.Bookmark = bk
application.echo true
End Sub

even with this i get an error "not a valid bookmark". but if i remove the echo statement i dont get the error.

do u know anything about this API mentioned before?
0
 
LVL 2

Accepted Solution

by:
bclark100898 earned 100 total points
Comment Utility
Is this buggy or what?  Thanks for the example.  From it I built a new form, which did not work.  I stared at it for a couple of hours and compared it to an existing form that has worked forever.  Here is what I learned.

First a few comments - For this sumbision, the simple examples used to test this code are too fast for me to see if the first record is flashed onto the screen.  I assume it does not.  I found what is needed for the form design, and only tested if the code itself runs or dies.  However, except for trapping errors, the code discussed herein is identical to the previous examples, which seemed to behave correctly.

This raises a valid point - fast code, simple datasets, no need for Echo.

That said....

If the code includes "application.echo off", then in order to work:

The form's OrderBy property must be set.
The form's OrderBy property must not be set to the first field of a primary key, even if the form's record source is a query.

1) I have not investigated the behavior of linked tables nor of joined tables.

2) The only way to positively identify the first field of a table's key is to View the table's index (in table design).

3) The easiest way to set the a form's OrderBy property is to open the form.  Click on a field.  Then, on the tool bar, click the AtoZ sort button or the ZtoA button.  The OrderBy property can also be set when designing the form.

If you close the form after setting the OrderBy property, the Command10 button will work the next time the form is opened.  However, if after setting the OrderBy property you keep the form open, then first time you subsequently click your Command10 button, it will fail.  After the failure, Command10 will work fine.

If we could requery the form right after it was sorted, the code would work 100% (except that field one of the table's key will always fails on any but the first record).  However, I don't don't think we can tap into any kind of a Sort Event, so perhaps we have to live with "100% success so long as no one clicks a sort button" and "98% success if they do".

Here is the same old code with an On Error statement in it.  The On Error takes care of those times someone clicks on a sort button, then a few records later, perhaps, clicks on your Command10 button.  In this case, the user will find themselves on the first record.

Public Function FormRequery()
   
    Dim CurrentRecord As String
   
    On Error GoTo oops
   
    Application.Echo False
   
    If Me.NewRecord Then
       
        Me.Requery
        DoCmd.GoToRecord acForm, Me.Name, acNewRec

    Else
       
        CurrentRecord = Me.Bookmark
        Me.Requery
        Me.Bookmark = CurrentRecord
   
    End If
   
oops:

    Application.Echo True
       
End Function


There is an API call, LockWindowUpdate, mentioned in the book "Visual Basic 5.0 Programmer’s Guide to the Win32 API", By Daniel Appleman.  It has the same effect on Access as the Echo method, complete with bugs.

The function returns nonzero on success and zero on failure (for example, only one window may be locked at a time).

This code goes in the form:

Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) as Long

Public Function FormRequery()
   
    Dim CurrentRecord As String
   
    On Error GoTo oops
   
    'Application.Echo False
    LockWindowUpdate Screen.ActiveForm.hwnd
   
    If Me.NewRecord Then
       
        Me.Requery
        DoCmd.GoToRecord acForm, Me.Name, acNewRec

    Else
       
        CurrentRecord = Me.Bookmark
        Me.Requery
        Me.Bookmark = CurrentRecord
   
    End If
   
oops:

    LockWindowUpdate 0  ' an argument of zero unlocks the window
    'Application.Echo True
       
End Function




0
 
LVL 5

Expert Comment

by:kulikuli
Comment Utility
I guess bclark came up with a really good answer on the API I mentioned. You should get it running by now, rolo.
0
 

Author Comment

by:rolo
Comment Utility
i guess your answer works if set to those specs.

the api doesnt work for anything. even without requery.

i have discovered a REMARKABLE discovery to solve my problem. it is so perfect i cant believe it. i am going to describe what i did, even though im not sure which part can be left out and achieve the same results.

ive created a blank modal popup form. in the sub that calls the requery, i first do
docmd.openform "whatever"
after the requerying is done i close it.
now that sounds simple enough. the remarkable thing about it is that the form NEVER OPENS. i dont know why. and i dont care why. the bottom line is the fact that it is theoretically open causes the screen not to show any update until that form is closed. but you never see the form. all you see is the main form that you are requerying.
dont ask me why this works but its perfect.
the only clues i can give is that my main form is a pop up but not a modal.

go figure.


as far as bclarks answer i would choose to keep the 100 points for myself but i dont know how
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now