Results 1 to 14 of 14
  1. #1
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109

    Loop animation (with Do..Loop) stops my other code

    Hi Guys,



    I've built a looper animation to entertain users while my code is saving data. It is quite simple form with 8 rectangles that dynamically change their RGB color to achieve an effect of "chasing tail". It works, but If I load it from other code, it stops the calling code from continuing..
    The animation uses 2 for..next loops and 1 do... Loop. It also contains DoEvents statement (otherwise it freezes few seconds after firing).
    What should I do to keep calling code continuing while my animation form is also running? In other words how to keep 2 forms (with 2 blocks of code) being processed at the same time?

    Robert

    EDIT: I did more searching and I learned that VBA doesn't support multithreading.. so it can't run code A and code B at the same time. It is either one code after another or the calling code stops until called code has finished and then starts where it previously stopped.. Not good... I found few workarounds but none actually worked good for me.

    I think this topic can be deleted or left of other interested

    Robert
    Last edited by robs23; 08-19-2014 at 08:01 AM.

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Here is an out of box idea I have tried. Not sure if it will work for you !! I am trying to learn Windows Presentation Foundation(WPF) and tried this trick based on it. WPF supports animation in big way, but a steep learning curve.
    • Create a text document. Copy and paste the below code, save and close. Change the file extension from .txt to .xaml. Try to open this .xaml file using Internet Explorer. If it shows color changes from red to blue and back, it is working correctly.

    Code:
    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <DockPanel >
    <Rectangle Name="Rect" Fill="Red" >
       <Rectangle.Triggers>
           <EventTrigger RoutedEvent="FrameworkElement.Loaded">
               <BeginStoryboard>
                  <Storyboard RepeatBehavior="Forever">
                     <ColorAnimation Storyboard.TargetProperty="Fill.Color" From="Red" To="Blue" Duration="0:0:2.0" AutoReverse="True"/>
                  </Storyboard>
                </BeginStoryboard>
           </EventTrigger>
          </Rectangle.Triggers>
       </Rectangle>
    </DockPanel>
    </Page>
    • Create a form (say frmAnimation), add a Web Browser control to it. Set its control source to this xaml file you saved.
    • Open this form as a hidden form when you load the form that is running your other code.This is required to avoid the delay till the animation starts.
    • Just before you start the code to save/manipulate data, make this form visible and hide again when code finishes execution.
    • Close frmAnimation just before you close your main form.

    The color animation will run infinitely and independent of your other code.
    I have used a simple animation of color changing rectangles. You can tweak the animation by editing the xaml file and test it by opening it in Internet Explorer.
    Happy coding !!

  3. #3
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Thanks mate!

    This is very similar to the workaround I use in this thread. The only difference is that I'm using animated gif rather than .xaml file. I encountered a problem that my gif freezes a second or so after it's been fired (please see the last post in that thread). Do you know why that might be? Doesn't your method suffer from this issue as well?

    Robert

  4. #4
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    It was working flawlessly in my case. Make sure
    Open this form as a hidden form when you load the form that is running your other code.This is required to avoid the delay till the animation starts.

  5. #5
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109

    Odp: Loop animation (with Do..Loop) stops my other code

    Quote Originally Posted by amrut View Post
    I have used a simple animation of color changing rectangles.
    Do you mean you had something like few rectangles changing colors or just one? Could you share your final code or provide any learning materials?

  6. #6
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Just one rectangle with color swinging between red and blue as you can see in code below
    <ColorAnimation Storyboard.TargetProperty="Fill.Color" From="Red" To="Blue" Duration="0:0:2.0" AutoReverse="True"/>
    Duration in hh:mm:ss format and color animation From="Red" To="Blue"

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    50,070
    Interesting but a lot of effort for a fancy hourglass effect.

    Tested with full screen display. Might need a warning for individuals prone to seizures triggered by bright flashing lights! Know anyone with epilepsy condition?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Yeah, agree. It's just hard to let it go once you have put quite a lot work already, you know? I guess it's everything against me and it probably doesn't make much sense to go on with this.. How can I programitacally change coursor for hourglass?

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    50,070
    Docmd.Hourglass True
    'run some code
    DoCmd.Hourglass False

    However, I am getting the spinning circle, not an hourglass with Access 2010.

    Be careful with using this. If code is interrupted before the False line then you are stuck with the spinning circle cursor. It will work, just a little disconcerting. Can always set it back by running command in Immediate Window. If you use error handler and exit procedure code, put the False line in the exit procedure.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    2,999
    Are you opening your 'animation' Form with acDialog as the WindowMode? This will always stop the execution of any ensuing code until the Dialog Form is closed. If this is the case try a different parameter (such as acWindowNormal) and see what happens.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  11. #11
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    @June7 Thanks.
    @Missinglinq In this case I use acWindowNormal but it still freezes. I guess it's all because of Access' singlethreading. I thought that if I load IE browser to a form then it will run independently to my main form but I was proven wrong. The other workaround I found is to use vbs file to open IE object and navigate to a .gif file. It works and all is good, though I don't like the IE title bar being visible and there's no way to hide it really. Probably there are some workarounds to this workaround but it's getting to complex and bug-vulnerable. It's just too much hassle getting this to work in my way, I think I'll be better off with simple hourglass.

    Robert

  12. #12
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    Use the form timer event for such kind of things. It allows you to call code in intervals and you won't need a loop that blocks the rest of the access. If there is another code running, the timer event will not fire, as long as you don't call DoEvents in that code, to give access the possibility to interrupt your work and handle the message event queue of the form.

  13. #13
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    @hapm Thanks for the pointers. I decided to let it go and now I have simple "Please wait.." pop-up and hourglass till loading is done. The overall impression didn't suffer that much, I would even say it is just as good. Anyway, even though I haven't found desired solution to my "animation" problem, I've learned few new things about Access and vba and that will definitely pay off in future

    So big thanks for you and other contributors in this and the other one topic!

    Robert

  14. #14
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Click image for larger version. 

Name:	p1.png 
Views:	14 
Size:	36.2 KB 
ID:	17866Click image for larger version. 

Name:	p2.png 
Views:	14 
Size:	47.4 KB 
ID:	17867
    These are screenshots of what I have tried. I have changed the colors to White and Red. I have a query which performs few calculations and then there is code looping through a recordset and performing few calculations. As mentioned earlier, I make this form visible when code starts and hide when it is completed.As you can see, the query is still running in background and colors swing between white and red.
    Anyway, as pointed by June, it is a lot of effort !!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 04-07-2014, 07:48 PM
  2. How to loop
    By psbailey42 in forum Programming
    Replies: 1
    Last Post: 09-26-2013, 12:11 PM
  3. Replies: 3
    Last Post: 03-10-2013, 07:04 AM
  4. Replies: 3
    Last Post: 10-19-2011, 01:05 PM
  5. How to loop code to run through entire table
    By kmajors in forum Reports
    Replies: 9
    Last Post: 04-23-2010, 09:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums