Max Wanadoo
max.wanadoo at gmail.com
Fri Mar 5 15:48:56 CST 2010
Thanks Brad, That actually won't work in my situation, but I have solved it. Here is the code below. We need to move into the projectpath folder and then run the batch BECAUSE in the projectpath folder we have the batch file call the blat.exe which has not been installed and is unknown to the system. BTW, the ChDir on itself is no good because that will not change the Folder (directory) so we need to use ChDrive as well. None of it can be "hard coded" because the folders could be anywhere. I appreciate the feedback though. Cheers Max Private Sub sShell(sFile) Dim strCurPath As String, strCurDrive As String, strProjPath As String, strProjDrive As String ' get the project location strProjPath = CurrentProject.Path strProjDrive = Left(strProjPath, 1): 'Debug.Print strProjDrive, strProjPath ' get the current location strCurPath = CurDir strCurDrive = Left(strCurPath, 1): 'Debug.Print strCurDrive, strCurPath ' change the current location to the project location ' so that we can run the blat.exe via the blat.bat file ChDrive strProjDrive ChDir strProjPath ' now run the batch file Shell sFile ' now restore the current location back to what it was. ChDrive strCurDrive ChDir strCurPath End Sub -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Brad Marks Sent: Friday, March 05, 2010 9:28 PM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Shelling to a batch file Max, I use the SHELL command quite a bit to fire-up .bat and .exe files from Access. Below is a snippet of VBA code which you may find useful. I am not sure if this will help you or not, but I thought that I would share what I have. Please let me know if you have any questions. Thanks, Brad Marks '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ Const Four_Quotes As String = """" Dim Var_String_For_Shell_Command Dim Var_Program_To_Be_Initiated Dim Var_Parm_Passed_To_Initiated_Program Var_Program_To_Be_Initiated = "C:\Documents and Settings\ABC\My Documents\InitXcel.bat" Var_Parm_Passed_To_Initiated_Program = "TEST-ABC" Var_String_For_Shell_Command = _ Four_Quotes _ & Var_Program_To_Be_Initiated _ & Four_Quotes _ & " " _ & Four_Quotes _ & Var_Parm_Passed_To_Initiated_Program _ & Four_Quotes MsgBox "Var_String_For_Shell_Command = " & vbLf & vbLf & Var_String_For_Shell_Command Shell Var_String_For_Shell_Command '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~ -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Max Wanadoo Sent: Thursday, March 04, 2010 3:36 PM To: 'Access Developers discussion and problem solving' Subject: [AccessD] Shelling to a batch file Hi All, I am struggling to get the SHELL command to run a batch file from Access. Any clues or tips? The batch file in turn will run and executable in the same folder as the currentproject.path BUT this exe file is NOT installed so it is necessary to ensure that I first move to that folder and then run the batch.bat file. Eg: g\_MyTest is my currentproject.path within Access In there I have blat.exe which is not installed and which I do not want to install - so nothing in the Registry. I also have blat.bat which I have created from Access. I want to run the batch file which in turn will invoke the blat.exe and pass it parameters. The batch file runs fine if manually invoked. This is the last bit of running Blat from within Access. I will then post the lot to the List. Thanks Max This is where I am at: Private Sub sShell(sFile) ' sfile will be "blat.bat" const conQuote as string = """" Dim sPath As String ' move into the current folder because we havn't installed Blat.exe sPath = conQuote & " CD /D " & CurrentProject.Path & conQuote Debug.Print sPath ShellExecute Application.hWndAccessApp, "Open", sPath, "", "", vbNormalFocus ' now run the batch file 'sFile = conQuote & sFile & conQuote Debug.Print sFile ShellExecute Application.hWndAccessApp, "Open", sFile, "", "", vbNormalFocus End Sub -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com