VBA to run a BAT file in ms access 2016 (1 Viewer)

virencm

Registered User.
Local time
Today, 17:05
Joined
Nov 13, 2009
Messages
61
Hi guys,

I am trying to run a bat file from a 2016 access database and i get an error "INVALID PROCEDURE CALL OR ARGUMENT".
The VBA code i am using is attached to a button

shell ("path\import_1.bat)

Am i missing something? is there a specific reference that is required for running bat files? I have the "windows script object model"referenced.

thanks for your help!

Cheers
V
 

Minty

AWF VIP
Local time
Today, 08:05
Joined
Jul 26, 2013
Messages
10,366
I think you would need a closing quote and the full path
shell ("c:\yourpath\import_1.bat")
 

vba_php

Forum Troll
Local time
Today, 02:05
Joined
Oct 6, 2019
Messages
2,884
I have this in my logs from years ago, so it seems that minty might be right:
Code:
Public Function CreateBat(fName As String)
     
'******************************************************************************
'                                                                             *
'Author:                                                        *
'Date: 10/2/2010                                                              *
'Purpose: Creates a single batch file, executes its code and then deletes it. *
'                                                                             *
'Arguments:                                                                   *
'fName > Full path and file name of the batch file you want to create.        *
'        If omitted, "c:\test.bat" will be created.                           *
'                                                                             *
'pListDelimiter > Separator you use for your list, as seen below:             *
'                       " "                                                   *
'                                                                             *
'******************************************************************************

If fName = "" Then
   MsgBox "Output filename must be specified..."
      Exit Function
End If

    Dim fNum As Integer
    Dim retVal As Variant
     
    fNum = FreeFile

      Open fName For Output As #fNum
         'Use "Print" statements here to write lines of the batch file.
         Print #fNum, "cd " & Chr(34) & "c:\" & Chr(34) 'Chr(34) = "
         Print #fNum, "DIR"
         Print #fNum, "exit"
      Close #fNum

    retVal = Shell(fName, vbHide)
     
      If retVal = 0 Then
         MsgBox "An Error Occured"
            Close #fNum
      End If
     
     'Delete batch file - OPTIONAL
    Kill fName
     
End Function '//LL
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:05
Joined
Feb 19, 2002
Messages
43,196
The FollowHyperlink method also works to open/run any file whose extension is properly registered with windows and takes only a single line of code.
 

strive4peace

AWF VIP
Local time
Today, 02:05
Joined
Apr 3, 2020
Messages
1,003
hi V,

if you want to know why Shell didn't work, here is a link that uses Shell, so you can see what is different.

Run Dos Batch files from Access
http://access.mvps.org/access/general/gen0015.htm

but maybe all you needed was the closing quote! assuming path was the full path as noted by Minty
 
Last edited:

Cronk

Registered User.
Local time
Today, 17:05
Joined
Jul 4, 2013
Messages
2,771
Note the missing quote before the closing bracket
 

Users who are viewing this thread

Top Bottom