473,387 Members | 1,529 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,387 software developers and data experts.

VBA problem in running .bat file

67 64KB
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:
Expand|Select|Wrap|Line Numbers
  1. FileName = CurrentProject.Path & "\Request_Budget_Expenditure\Request_Budget_Expenditure_run.bat"
  2.         Call WaitResponse.ShellWait(FileName, 1)
Function definition:
Expand|Select|Wrap|Line Numbers
  1. 'This module is about run .bat file and then wait for program to finish running
  2.  
  3. Private Const STARTF_USESHOWWINDOW& = &H1
  4. Private Const NORMAL_PRIORITY_CLASS = &H20&
  5. Private Const INFINITE = -1&
  6.  
  7.  
  8. Private Type STARTUPINFO
  9.     cb As Long
  10.     lpReserved As String
  11.     lpDesktop As String
  12.     lpTitle As String
  13.     dwX As Long
  14.     dwY As Long
  15.     dwXSize As Long
  16.     dwYSize As Long
  17.     dwXCountChars As Long
  18.     dwYCountChars As Long
  19.     dwFillAttribute As Long
  20.     dwFlags As Long
  21.     wShowWindow As Integer
  22.     cbReserved2 As Integer
  23.     lpReserved2 As Long
  24.     hStdInput As Long
  25.     hStdOutput As Long
  26.     hStdError As Long
  27. End Type
  28.  
  29. Private Type PROCESS_INFORMATION
  30.     hProcess As Long
  31.     hThread As Long
  32.     dwProcessID As Long
  33.     dwThreadID As Long
  34. End Type
  35.  
  36. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
  37.     hHandle As Long, ByVal dwMilliseconds As Long) As Long
  38.  
  39. Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
  40.     lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
  41.     lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
  42.     ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
  43.     ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
  44.     lpStartupInfo As STARTUPINFO, lpProcessInformation As _
  45.     PROCESS_INFORMATION) As Long
  46.  
  47. Private Declare Function CloseHandle Lib "kernel32" (ByVal _
  48.     hObject As Long) As Long
  49.  
  50.  
  51. ' To run .bat file and until that program finish running
  52.  
  53. Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
  54.     Dim proc As PROCESS_INFORMATION
  55.     Dim start As STARTUPINFO
  56.     Dim ret As Long
  57.     ' Initialize the STARTUPINFO structure:
  58.     With start
  59.         .cb = Len(start)
  60.         If Not IsMissing(WindowStyle) Then
  61.             .dwFlags = STARTF_USESHOWWINDOW
  62.             .wShowWindow = WindowStyle
  63.         End If
  64.     End With
  65.     ' Start the shelled application:
  66.     ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, _
  67.             NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
  68.     ' Wait for the shelled application to finish:
  69.     ret& = WaitForSingleObject(proc.hProcess, INFINITE)
  70.     ret& = CloseHandle(proc.hProcess)
  71. End Sub
  72. '***************** Code End ****************
  73.  
  74.  
  75.  
  76.  
  77.  
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
Mar 13 '14 #1
1 1579
sophannaly
67 64KB
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
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE request_expenditure SET revision=" & old_revision
  2.         db.Execute strSQL, dbFailOnError
  3.  
  4.         MsgBox db.RecordsAffected & " record(s) affected."
  5.  
  6.         FileName = CurrentProject.Path & "\Request_Budget_Expenditure\Request_Budget_Expenditure_run.bat"
  7.         'Call ShellWait(FileName)
  8.         Call waitfiletorun.ShellWait(FileName)
Mar 14 '14 #2

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

Similar topics

4
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...
8
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,...
8
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...
4
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,...
5
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...
9
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?
10
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...
3
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. ...
8
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...
1
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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
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
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...

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.