Hi,
I do have problem with running .bat file in vba. The problem is if I run .bat file directly(not via vba), I will get the correct result. If I run in debug mode, I will get the correct result as directly run .bat file too. But if I run it from vba, then I will get the incorrect result. Below is my code about how I call my bat file and its function: - FileName = CurrentProject.Path & "\Request_Budget_Expenditure\Request_Budget_Expenditure_run.bat"
-
Call WaitResponse.ShellWait(FileName, 1)
Function definition: - 'This module is about run .bat file and then wait for program to finish running
-
-
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, lpProcessInformation As _
-
PROCESS_INFORMATION) As Long
-
-
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
-
hObject As Long) As Long
-
-
-
' To run .bat file and until that program finish running
-
-
Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
-
Dim proc As PROCESS_INFORMATION
-
Dim start As STARTUPINFO
-
Dim ret As Long
-
' Initialize the STARTUPINFO structure:
-
With start
-
.cb = Len(start)
-
If Not IsMissing(WindowStyle) Then
-
.dwFlags = STARTF_USESHOWWINDOW
-
.wShowWindow = WindowStyle
-
End If
-
End With
-
' Start the shelled application:
-
ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, _
-
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
-
' Wait for the shelled application to finish:
-
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
-
ret& = CloseHandle(proc.hProcess)
-
End Sub
-
'***************** Code End ****************
-
-
-
-
-
I already tested it many times, and I just have no idea why the same program but different result between run in debug mode and run mode.
Please tell me how do solve about this problem.
Best regards,
Sophanna
1 1579
Hi,
I found solution but i'm not sure is it like that but it works for me. I think this problem is about running speed update to table and upload these data to remote DB via bat file.So I have please a pop up message between these two functions as - strSQL = "UPDATE request_expenditure SET revision=" & old_revision
-
db.Execute strSQL, dbFailOnError
-
-
MsgBox db.RecordsAffected & " record(s) affected."
-
-
FileName = CurrentProject.Path & "\Request_Budget_Expenditure\Request_Budget_Expenditure_run.bat"
-
'Call ShellWait(FileName)
-
Call waitfiletorun.ShellWait(FileName)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brad Smith |
last post by:
I have a unique requirement to run an executable file from withing a
HTML document. The HTML is actually embedded in an email sent as a
notification to a user of our application. I need to include...
|
by: Lam |
last post by:
HI
anyone knows how can I open a mapped network file in C#?
I try string file = @"T:\file.txt"; it shows me the error: "Could not find
a part of the path"
but if I copy the file to my C dirve,...
|
by: Alphonse Giambrone |
last post by:
I have a small asp.net web app running on a shared host.
It uses a Jet (Access) database. I included a routine to compact the
database when the application_event fires if it has not been compacted...
|
by: Lance |
last post by:
Are there any methods that indicate whether a string can be used as a full path for a file? For example, what I'm looking for is a method that would test for things like correct file name format,...
|
by: ^cypis^ vel. SQ9JTI |
last post by:
Hi there,
i have a problem. I prepared bucket sorting with reading values from
file (data.txt) and saving to other file (aus.txt).
Everything is good if we talk about reading and sorting, but...
|
by: windmill |
last post by:
I received the error message "unexpected $end" on a file while running the script under Windows (Apache 2); runs without error on Linux (Apache 1). Any suggestions?
|
by: Evyn |
last post by:
HI all,
I have a text file of integers. I can format the file so that the
integers are 1 per line, or continuous.
Reading the file is not a problem. What I want to do is sum the
integers and...
|
by: maheshkadam |
last post by:
Hi friends
I am new to perl so please guide me.
I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only.
...
|
by: geert |
last post by:
Hi all,
I have a mac mini running maocosx 10.5 leopard I want to deploy a
django project on. My backend is MySQL, and I have it running as a 64-
bit app. Of course, apache2 is also running as...
|
by: =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?= |
last post by:
On reflection, you could possibly make the app a self extracting zip file
which extracts the EXE and a settings file and then starts the app, then when
you app closes, it can repack the settings...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
| |