+ Reply to Thread
Results 1 to 16 of 16

Long running vb/a code Issues

  1. #1
    Registered User
    Join Date
    02-07-2012
    Location
    98052
    MS-Off Ver
    Excel 2003
    Posts
    15

    Question Long running vb/a code Issues

    Hi All,

    I need some advice to getting excel, a user form and vb/a to play nice with each other and the os.

    I have a user form w/ vb code that can run for a minute to an hour depending on what parameters the user selects.

    When the code is running and excel minimized, it can't be restored until the code completes.
    additionally,
    if I select the form and try to move it there is a few minute delay before it happens
    if a application is opened over the user form or excel, then closed, the user form and excel image is blanked and doesn't repaint for several minutes.
    on occasion, when I open task manager, I see excel and MS VB for Appl. in a non responding state
    There isnm't any issues displayed in task mngr, the machine is running at about 45% cpu utilization.
    However, other apps, appear slow to respond at times when the vb code is running.

    I've sprinkled do events and repaint through out the code modules but it's a poor attempt at best.

    Also the code appears to sporadically hang, if I hit a ctrl+Break, then resume, the code continues
    however, at the break point, I add another DoEvents

    Is there something I've over looked?

    thanks
    Last edited by toddbailey; 03-02-2012 at 02:19 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Long running vb/a code Issues

    toddbailey,

    Usually when code takes a long time to run, its due to inefficiencies in the code-writing, like using unnecessary loops, sifting through unnecessary data, or making multiple changes directly to the worksheet instead of using arrays.

    Without seeing the code, its difficult to say what the problem is. So...
    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    02-07-2012
    Location
    98052
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Long running vb/a code Issues

    let's assume the code is optimized

    basically the vba code makes a lot of calls to a back-end database(access via ado) for data preparation, there is little the front end does, but wait for the back-end data base to finish the query, only until the very end there are 1/2 a dozen calls used to populate worksheets and run effectively.

    I'm looking for a way to make excel and the user form more responsive to windows events, while the code is running. The addition of doevents have helped, but regardless of what the code is doing in the background, the userform and excel shouldn't be locked out from basic windows functions.

    Maybe I need to port the code to C# and run the data prep process as a batch job and once the data is prepared,
    the user can run a stripped down version to populate the sheet
    Last edited by toddbailey; 03-02-2012 at 03:17 PM.

  4. #4
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Long running vb/a code Issues

    If we assume the code is optimised, that doesn't really leave us anything to say, as far as I can see.
    Good luck.

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Long running vb/a code Issues

    One idea (I can't take credit, it goes to forum user darkyam):

    instead of numerous calls to another database, might it be faster to copy the necessary section of data, post it in the current workbook, work from there, and then delete those pages when finished? Just an idea.

  6. #6
    Registered User
    Join Date
    02-07-2012
    Location
    98052
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Long running vb/a code Issues

    Excel is just the reporting application, we are talking about thousands of records the database has to work through.
    Once the data is prepared, the population of the worksheets is very straight forward. basically a simple do while not eof loop

    So, I ask again, Is there any settings I can make to excel, the user form or other properties that would make the execution of the code more transparent so either respond when excel is minimized, after all last I checked Windows is still multi tasking os?

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Long running vb/a code Issues

    The answer is: post your workbook /code here.



  8. #8
    Registered User
    Join Date
    02-07-2012
    Location
    98052
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Long running vb/a code Issues

    Sorry NDA prevents that, legal issues, Besides, we are talking several hundred lines of code. Each sub assembly has manf. processes that occur equipment setup times, and various operator time as well, each sub assembly has 10 different cost models, each sub assembly has different countries of manufacture with different labor rates. It just would be practical for me to post all the code utilized to calculate all these parameters. Before I went to a user form model, the various run time parameters were entered in a worksheet. There wasn't any of these issues I'm seeing with a user form.

    So PLEASE, I need general ideas on what setting should/could be made to excel or user form to minimize code run time issues. This stuff isn't rocket science...
    Last edited by toddbailey; 03-02-2012 at 05:15 PM.

  9. #9
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Long running vb/a code Issues

    Well, if you ring up your garage and tell them that your car is making funny noises, do you expect them to solve the problem without you bringing in the car? After all, fixing a car is not rocket science, either.

    cheers,

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Long running vb/a code Issues

    Well, in that case use this

    Please Login or Register  to view this content.

  11. #11
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Long running vb/a code Issues

    Thousands of records and hundreds of lines of code really isn't all that much. I have a workbook I did for a friend that pulls in about 40k-45k records when it refreshes the data, which it does every time the file opens and every time they change the date in a certain cell. It takes maybe a second to load all that raw data into a separate sheet. Then it is just a matter of having formulas extract, sum or otherwise calculate that data.

    If your connections take a long time, or even time out, then it stands to reason that you should make as few connections as possible.

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Long running vb/a code Issues

    1) Turn off screen updating
    2) Don't loop row by row doing the same thing, see if you can process the entire dataset all at once.
    3) If looping is a must, reduce calls to the sheet by loading the data into an array, loop through the array, then put the array back onto the sheet... a total of 2 calls to the sheet even if the array was 50k values
    4) Post parts of your code for others to examine and look for ways to optimize further.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  13. #13
    Registered User
    Join Date
    02-07-2012
    Location
    98052
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Long running vb/a code Issues

    Quote Originally Posted by teylyn View Post
    Well, if you ring up your garage and tell them that your car is making funny noises, do you expect them to solve the problem without you bringing in the car? After all, fixing a car is not rocket science, either.

    cheers,
    I don't know about that have you tried to fix a modern computer controlled vehicle lately?
    If replacing plugs, distrib. cap rotor or plug wires you'screwed...

  14. #14
    Registered User
    Join Date
    02-07-2012
    Location
    98052
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Long running vb/a code Issues

    Quote Originally Posted by snb View Post
    Well, in that case use this

    Please Login or Register  to view this content.

    I wonder if I were to put application.quit in a button if I could use it to abort the code execution?
    A request to provide a cancel button was brought up.

  15. #15
    Registered User
    Join Date
    02-07-2012
    Location
    98052
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Long running vb/a code Issues

    I found the problem, it's network related, where ado was getting disconnected from the database. I'll have to research ado connections and see if a timeout parameter exists
    If I copy the mdb file to a local drive, execution speeds up significantly, screen response issues go away.

    I've already turned off screen updating and open the form as open modal = false

    But fyi: the first part of the code design doesn't do anything with excel, just a lot of data processing against the backend database, if this were a sql backend, I'd be using stored procedures, but access doesn't have the ability, unless I can call a code module in the backend from the excel front end.

  16. #16
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Long running vb/a code Issues

    Are you using asynchronous queries? That also might improve the performance on the front end (albeit requiring more code).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1