设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 881|回复: 2
打印 上一主题 下一主题

[与其它组件] access 调用程序问题

[复制链接]
跳转到指定楼层
1#
发表于 2006-10-23 19:53:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
现在需要通过一个按钮调用两个程序,我用两个call命令分别调用,但我发现两个程序是同时调用的,我希望执行完一个程序在执行另一个程序,如何解决呢?

Dim stAppNametransfer As String

    stAppNametrans = "d:\trans.bat"
   
    Call Shell(stAppNametrans, 1)
   
    Dim stAppName1 As String

    stAppNamersh = "c:\program files\1.exe"
   
    Call Shell(stAppName1, 1)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2006-10-24 00:29:00 | 只看该作者
另一个程序放在"计时器触发"事件中,利用"计时器间隔"来执行
3#
发表于 2006-10-24 03:46:00 | 只看该作者
Shell执行程序是异步执行的,所以不能实现你的要求,当然这也不是没有办法。

摘自:access911.net

方法1:

我们用shell()来执行外部的程序时,一旦shell启动了外部程序后无论外部程序是否已经运行完毕,Access 都会继续执行 shell 语句下面的 VBA 程序。若要 Access 等待 shell() 调用的外部程序执行完毕后再继续执行下面的 VBA 程序可使用以下方法:









'以下语句加入窗体声明段
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredaccess&, ByVal bInherithandle&, ByVal dwProcessid&) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpexitcode As Long) As Long
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400



Dim hShell As Long
Dim hProc As Long
Dim lExit As Long









'更改您的shell语句为如下格式:
    hShell = Shell("RunExeFile", 1)



    hProc = OpenProcess(PROCESS_QUERY_INFORMATION, False, hShell)
   
    If hShell = 0 Then MsgBox "程序执行失败"

    Do
        GetExitCodeProcess hProc, lExit
        DoEvents
    Loop While lExit = STILL_ACTIVE

    MsgBox "Shell 语句执行完毕"

方法2:

将下列代码粘贴到一个新模块中,并使用ShellWait过程调用外部程序。





<TABLE 100%" cellSpacing=1 cellPadding=5>



<TR>

<TD #81a9e8 1px solid; PADDING-RIGHT: 10px; BORDER-TOP: #81a9e8 1px solid; MARGIN-TOP: 0px; PADDING-LEFT: 10px; PADDING-BOTTOM: 10px; BORDER-LEFT: #81a9e8 1px solid; COLOR: #00284d; PADDING-TOP: 10px; BORDER-BOTTOM: #81a9e8 1px solid; BACKGROUND-COLOR: #f2f2f2; TEXT-DECORATION: none" width="100%">'***************** Code Start ******************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Terry Kreft
Private Const STARTF_USESHOWWINDOW& = &H1
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&



Private Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type

Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessID As Long
    dwThreadID As Long
End Type

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
    hHandle As Long, ByVal dwMilliseconds As Long) As Long
   
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
    lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
    lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
    ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
    ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
    lpStartupInfo As STARTUPINFO, lpProcessInformat
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-9-22 04:14 , Processed in 0.077505 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表