在VBA代码执行期间刷新消息窗口/文本框 [英] Refresh message window/textbox during VBA code execution

查看:761
本文介绍了在VBA代码执行期间刷新消息窗口/文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在MS Access 2003中开发了一些VBA代码,在执行期间,我打印消息,指示活动表单文本框中的整体进度(以及底部状态栏)。确切地说,我使用Fortran DLL通过VBA回调函数传递其消息,但我不认为这对问题很重要。


问题是一旦我专注于另一个应用程序,MS Access就会冻结自己。我的意思是,当我回到Access时,光标变成了一个时钟,并且在代码执行结束之前没有刷新,因此破坏了我为用户提供执行信息所做的所有努力。


有没有办法解决这个问题?


谢谢


布鲁诺

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

推荐答案

  1. 如何发布您的VBA代码?
  2. 您如何关注外部应用程序,自动化?
  3. 听起来.DLL例程可能正在同步执行,可能是这种情况吗?
  4. 您是否尝试在代码块中使用DoEvents定期放弃控制权Windows环境?


看来这是由调用外部代码而不是手动切换到你问题中所述的另一个appliocation来触发的。 br />

如果你指出外部公司如何表示会有所帮助de被调用,但我确定它是同步调用。这将代码作为同一过程的一部分运行。访问将等到控制权返回之后再进行响应。就Access而言,它是忙碌
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.


代码很长但是很快就要描述它我使用Declare语句来声明dll:


声明Sub HFprediction Lib" Z:\ GlobalHF \ HFF; \\ GLOBHEAT \ f90HFprediction\HFpredict ion.dll" (...,ByVal pCallbackFunc As Long)


,最后一个参数对应于回调函数。然后我在点击OK按钮时简单地调用dll:


调用HFprediction(...,AddressOf Callback)


回调为a简单的VBA子程序来显示消息:


sub回调(字符串)

debug.print string

Application.Forms(" HF_prediction"。。TxtMessages = string

SysCmd(acSysCmdSetStatus,string)

end sub


我认为我所做的是同步调用(虽然我真的不知道这意味着什么),我想只要DLL运行,MS Access就会认为自己很忙,这会阻止它刷新自己并显示DLL通过回调发送的消息。我认为有一种方法可以告诉Access偶尔刷新一次,例如每次调用回调函数时,我都找不到。
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.


这篇关于在VBA代码执行期间刷新消息窗口/文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆