473,419 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Refresh message window/textbox during VBA code execution

7
Hi all,

I developed some VBA code in MS Access 2003, and during execution I print messages indicating the overall progress in a textbox of the active form (and also in the bottom status bar). To be precise I use a Fortran DLL which passes its messages through a VBA callback function, but I don't think it's important for the problem.

The problem is that once I focus on another application, MS Access freezes itself. I mean, when I come back to Access, the cursor turns into a clock and there is no refreshing until the end of code execution, hence spoiling all the efforts I made to give the user some info on execution.

Is there a way to handle that problem ?

Thanks

Bruno
Sep 23 '08 #1
12 14372
ADezii
8,834 Expert 8TB
  1. How about Posting your VBA code?
  2. How are you 'Focusing' on the External Application, Automation?
  3. It sounds like the .DLL routine may be executing synchronously, could this be the case?
  4. Have you tried using DoEvents in the code block to periodically relinquish control to the Windows Environment?
Sep 23 '08 #2
NeoPa
32,556 Expert Mod 16PB
It seems this is triggered by the calling of the external code rather than your manually switching to another appliocation as stated in your question.

It would help if you indicated how the external code is invoked, but I'm certain it is a synchronous call. This runs code as part of the same process. Access will wait until control is returned to it before it responds further. As far as Access is concerned it is Busy.
Sep 23 '08 #3
bnono
7
Well the code is quite long but to describe it shortly I use a Declare statement to declare the dll:

Declare Sub HFprediction Lib "Z:\GlobalHF\HF\GLOBHEAT\f90HFprediction\HFpredict ion.dll" ( ..., ByVal pCallbackFunc As Long )

with the last argument corresponding to the callback function. Then I simply call the dll when clicking on a OK button:

call HFprediction(..., AddressOf Callback)

Callback being a simple VBA subroutine to display messages:

sub Callback(string)
debug.print string
Application.Forms("HF_prediction").TxtMessages = string
SysCmd(acSysCmdSetStatus, string)
end sub

I think that what I do is a synchronous call (though I don't really know what that means), and I guess that MS Access considers itself busy as long as the DLL runs, which prevents it from refreshing itself and showing the messages sent by the DLL through the callback. I thought that there was a way to tell Access to refresh itself once in a while, for example each time the callback function is called, but I couldn't find how.
Sep 23 '08 #4
FishVal
2,653 Expert 2GB
Hello, bnono.

Does the same happen if the callback function contains no code ?

Regards,
Fish
Sep 23 '08 #5
NeoPa
32,556 Expert Mod 16PB
This is just as in-line or synchronous as calling a VBA function (like Format()).

However, if you get callbacks from within the routine where you update your screen, you need to revisit ADezii's point #4 and use DoEvents in your update code.
Sep 23 '08 #6
FishVal
2,653 Expert 2GB
I'm almost sure the problem is not with callback itself.
I've just now tested WinAPI timer with callback function that modifies Textbox content on a form. It works fine when Access window is inactive as well as when it is minimized.

Check whether your callback doesn't return to calling DLL or maybe reentered.
Sep 23 '08 #7
bnono
7
ok that works! I simply added a DoEvents() at the end of the Callback function, as suggested. I did not know that function, I was rather looking for sth like Application.Refresh

Anyway I guess that's it's a quick'n'dirty way to handle the problem (a Timer control may be a better choice), but that's enough in my simple case.

Thanks again for your advices

Bruno
Sep 23 '08 #8
NeoPa
32,556 Expert Mod 16PB
Glad to see it's resolved Bruno :)

Welcome to Bytes!
Sep 23 '08 #9
ADezii
8,834 Expert 8TB
ok that works! I simply added a DoEvents() at the end of the Callback function, as suggested. I did not know that function, I was rather looking for sth like Application.Refresh

Anyway I guess that's it's a quick'n'dirty way to handle the problem (a Timer control may be a better choice), but that's enough in my simple case.

Thanks again for your advices

Bruno
Since we have no visual cue as to what your code is doing, one precautionary note on DoEvents() which may/may not be applicable here. Avoid using DoEvents for each and every Iteration of an intensive Loop since it will gobble up resources. In the example below, the code releases control to the Windows Environment for every 100,000 iterations of the Loop. As previously stated, this may not be applicable, and you may also have to tweek how many time you use the DoEvents() Function.
Expand|Select|Wrap|Line Numbers
  1. Dim lngCounter As Long
  2. Dim varVal As Variant
  3.  
  4. DoCmd.Hourglass True
  5.  
  6.   For lngCounter = 1 To 20000000
  7.     varVal = lngCounter \ 37.968
  8.     If lngCounter Mod 100000 = 0 Then
  9.       DoEvents
  10.     End If
  11.   Next
  12.  
  13. DoCmd.Hourglass False
P.S. - Just out of curiosity, bnono. Using a Fortran .DLL to pass Messages via a VBA Callback Function, then display some Text in a Text Box, in order to indicate the relative completion percentage of some process, seems a little extreme. There are many other, much simpler, means to accomplish this. Why this approach?
Sep 23 '08 #10
bnono
7
@ADezii:

in fact i'm a geophysicist and as such I use Access to manipulate geophysical data. Also you may know that we scientists still like to use good old Fortran for data processing, because it's fast and efficient (faster than vba, at least) and also because it's an old habit. This explains I use a lot this combination of VBA (for GUI) and Fortran DLL (for data processing). Then the problem is that my DLL can run for hours, so I want to have some feedback once in a while, hence the use of a callback function... In fact I don't simply use it to display a simple progress bar, but various messages concerning the state of the program. Until now I was simply doing that by writing the messages to a file and then sometimes checking that file, but I found that printing the messages directly to my Access User form was more friendly. Since I call the callback function from my DLL only once in a while (say, every 10 s), it's ok to use DoEvent, which is not encapsulated into a wasting-resources loop.

Hope this sounds reasonable to you... That being said I know Fortran better than VBA, and if you have suggestions of simpler way to achieve what I want to do, please tell me !

Now I've got another question... : is there simple a way to unload the DLL after it has been called, other than reinitializing the VBA project? That's only a detail, but I constantly have to modify and recompile the DLL, and it's a bit annoying to always reinitialize the VBA project to be able to do so.

Regards,

Bruno
Sep 24 '08 #11
NeoPa
32,556 Expert Mod 16PB
Hi Bruno.

That explanation seems to be quite sensible. My brother's a geophysicist, and he's recently got into Access too, to handle some of the enormous datasets he has to deal with (although he mainly still works in Excel - his comfort zone ;)).

Anyway, I suspect there's no way of unloading a module once it's been initialised. As it's code outside the control of Access, it's quite reasonable for Access to require a reset when it is changed. Even adding/removing multiline code or constants in VBA requires the resetting of the running code I'm afraid.
Sep 24 '08 #12
ADezii
8,834 Expert 8TB
@ADezii:

in fact i'm a geophysicist and as such I use Access to manipulate geophysical data. Also you may know that we scientists still like to use good old Fortran for data processing, because it's fast and efficient (faster than vba, at least) and also because it's an old habit. This explains I use a lot this combination of VBA (for GUI) and Fortran DLL (for data processing). Then the problem is that my DLL can run for hours, so I want to have some feedback once in a while, hence the use of a callback function... In fact I don't simply use it to display a simple progress bar, but various messages concerning the state of the program. Until now I was simply doing that by writing the messages to a file and then sometimes checking that file, but I found that printing the messages directly to my Access User form was more friendly. Since I call the callback function from my DLL only once in a while (say, every 10 s), it's ok to use DoEvent, which is not encapsulated into a wasting-resources loop.

Hope this sounds reasonable to you... That being said I know Fortran better than VBA, and if you have suggestions of simpler way to achieve what I want to do, please tell me !

Now I've got another question... : is there simple a way to unload the DLL after it has been called, other than reinitializing the VBA project? That's only a detail, but I constantly have to modify and recompile the DLL, and it's a bit annoying to always reinitialize the VBA project to be able to do so.

Regards,

Bruno
NeoPa alreadly answered the question for you:
VBA dynamically loads code into memory as needed on a module level. If a function is called or a variable is used, the entire module containing that function or variable is loaded into memory. As you are developing your application, you keep loading code into memory. Visual Basic for Applications does not support dynamic unloading of these modules.
Sep 24 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bilal | last post by:
Hi, I'm a complete beginner in Javascript and php ... so forgive me for asking an easy/simple solution to the following problem: I'm developing an application that involves multi-screen in...
4
by: Alex Bibiano | last post by:
I have a typed dataset in my WinForm and a textbox with databinding to the dataset (all without code). Now, in a button event, I assign a new dataset (retrieved from a function) to the dataset a...
3
by: Steve Wark | last post by:
I have created a ASP.NET application and created two forms within the application (Webform1.aspx & Webform2.aspx). On the first form I have placed a textbox (TextBox1) and a button, which when...
9
by: PK9 | last post by:
I'm having an issue with the "Refresh" of an asp.net page. The refresh is actually calling my last onClick event. I thought that asp.net was supposed to be stateless in that it shouldn't...
3
by: Opa | last post by:
Hi , I have a form with javasript which launches a popup via the showModalDialog() method. I get the dialog to open, now I am trying to first get a reference to the calling form from the popup...
10
by: phforum | last post by:
Hi, I wrote a PHP page for user input the information to search the database. And the database data will update every second. I want to set the auto refresh to get the data from database every...
4
by: dancer | last post by:
I get this error if an item in a radiobutton list is not chosen when filling in a form.. I added a RequiredFieldValidator, but I still get the message. Object reference not set to an instance of...
4
by: Perl Beginner | last post by:
I have created a GUI window using Perl Win32::XMLBuilder. This window has several buttons on it, that when a button is clicked another Perl script will execute. When the script is complete, the GUI...
3
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
Ok guys, refresh my memory. I have a vague memory from years ago of a Dot Net 1.1 web app in which one window was opened from another (not a message box or anything like that, but a fully separate...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.