if exist ""C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE"" (
"Q:\Development Lab Test Requests\DataBase\Development Lab Project Requests DB.accdb" /x mcrEmail /cmd 1716
goto install
) else if exist ""C:\Program Files (x86)\Microsoft Office\Office16\MSACCESS.EXE"" (
"Q:\Development Lab Test Requests\DataBase\Development Lab Project Requests DB.accdb" /x mcrEmail /cmd 1716
goto install
)
Project: 1716
Batch File To Start Access and open to the submitted request record.
if exist "C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" goto Start
if exist "C:\Program Files (x86)\Microsoft Office\Office16\MSACCESS.EXE" goto Start
goto :eof
:Start
start "" "Q:\Development Lab Test Requests\DataBase\Development Lab Project Requests DB.accdb" /x mcrEmail /cmd 1716
if exist "C:\Program Files (x86)\Microsoft Office\root\Office14\MSACCESS.EXE" goto Start
if exist "C:\Program Files (x86)\Microsoft Office\Office16\MSACCESS.EXE" goto Start
goto :eof
:Start
Start "" "K:\R&D Dept\Development Lab\R&D Test Request System (For testing and training)\DataBase\R&D Project Requests DB.accdb" /x mcrEmail /cmd 1695
set Access14=C:\Program Files (x86)\Microsoft Office\root\Office14\MSACCESS.EXE
set Access16=C:\Program Files (x86)\Microsoft Office\Office16\MSACCESS.EXE
if exist "%Access14%" (
set Access=%Access14%
goto Start
)
if exist "%Access16%" (
set Access=%Access16%
goto Start
)
goto :eof
:Start
start "" "%Access%" "K:\R&D Dept\Development Lab\R&D Test Request System (For testing and training)\DataBase\R&D Project Requests DB.accdb" /x mcrEmail /cmd 1695
"%Access%" "K:\R&D Dept\Development Lab\R&D Test Request System (For testing and training)\DataBase\R&D Project Requests DB.accdb" /x mcrEmail /cmd 1695
set Access14=C:\Program Files (x86)\Microsoft Office\root\Office14\MSACCESS.EXE
set Access16=C:\Program Files (x86)\Microsoft Office\Office16\MSACCESS.EXE
if exist "%Access14%" (
set Access=%Access14%
goto Start
)
if exist "%Access16%" (
set Access=%Access16%
goto Start
)
echo ERROR: Found no install of Microsoft Access
exit 1
goto :eof
:Start
echo Found Microsoft Access: %Access%
REM start "" "%Access%" "K:\R&D Dept\Development Lab\R&D Test Request System (For testing and training)\DataBase\R&D Project Requests DB.accdb" /x mcrEmail /cmd 1695
"%Access%" "K:\R&D Dept\Development Lab\R&D Test Request System (For testing and training)\DataBase\R&D Project Requests DB.accdb" /x mcrEmail /cmd 1695
set Access14=C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Access.exe
set Access16=C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Access.exe
if exist "%Access14%" (
set Access=%Access14%
goto Start
)
if exist "%Access16%" (
set Access=%Access16%
goto Start
)
echo ERROR: Found no install of Microsoft Access
exit 1
goto :eof
:Start
echo Found Microsoft Access: %Access%
REM start "" "%Access%" "K:\R&D Dept\Development Lab\R&D Test Request System (For testing and training)\DataBase\R&D Project Requests DB.accdb" /x mcrEmail /cmd 1695
"%Access%" "K:\R&D Dept\Development Lab\R&D Test Request System (For testing and training)\DataBase\R&D Project Requests DB.accdb" /x mcrEmail /cmd 1695
because that is where my Access.exe is.Public Function BuildBatchfile(Counter As Integer)
Dim fnum As Variant
Dim MyFile As String
'first set a string which contains the path to the file you want to create.
'this example creates one and stores it in the root directory
MyFile = c_Main_Drive & c_Main_Folder & c_Main_BatchFiles & "Project " & Counter & " " & Format(Date, "mm-dd-yyyy") & ".bat"
'set and open file for output
fnum = FreeFile()
Open MyFile For Output As fnum
'Batch file to open Access
Print #fnum, "if exist " & Chr(34) & Chr(34) & "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" & Chr(34) & Chr(34) & " (" & vbCrLf & Chr(34) & c_Main_Drive & c_Main_Folder & c_Main_Database_Folder & c_ReqDBName & Chr(34) & " " & "/x mcrEmail /cmd " & Counter & vbCrLf & "goto install" & vbCrLf & ") else if exist " & Chr(34) & Chr(34) & "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" & Chr(34) & Chr(34) & " (" & vbCrLf & Chr(34) & c_Main_Drive & c_Main_Folder & c_Main_Database_Folder & c_ReqDBName & Chr(34) & " " & "/x mcrEmail /cmd " & Counter & vbCrLf & "goto install" & vbCrLf & ")"
Write #fnum,
'write project info and then a blank line. Note the comma is required
Print #fnum, "Project: " & Counter
Write #fnum,
'use Print when you want the string without quotation marks
Print #fnum, "Batch File To Start Access and open to the submitted request record."
Close #fnum
'BuildBatchFile = "Project " & Counter & " " & VBA.Format(Date, "mm-dd-yyyy") & ".bat"
End Function
I'm having trouble converting yours to a vba written batch file. Was trying like thisPublic Function BuildBatchFile(Counter As Integer) As String
Dim fnum As Variant
Dim MyFile As String
'first set a string which contains the path to the file you want to create.
'this example creates one and stores it in the root directory
MyFile = c_Main_Drive & c_Main_Folder & c_Main_BatchFiles & "Project " & Counter & " " & Format(Date, "mm-dd-yyyy") & ".bat"
'set and open file for output
fnum = FreeFile()
Open MyFile For Output As fnum
'Batch file to open Access
fnum = fnum & "@echo off"
fnum = fnum & " setlocal"
fnum = fnum & " for /f"
fnum = fnum & " tokens=2 delims=="
fnum = fnum & " %%a in ('ftype accesshtmlfile') do set Access=%%a"
fnum = fnum & " if not defined Access ("
fnum = fnum & " echo No Access installation found!"
fnum = fnum & " exit /b 1"
fnum = fnum & " )"
fnum = fnum & " echo Found Access: %Access%"
fnum = fnum & "s tart "" & " & "%Access% " & "K:\R&D Dept\Development Lab\R&D Test Request System (For testing and training)\DataBase\R&D Project Requests DB.accdb" & "/x mcrEmail /cmd 1695"
fnum = fnum & " exit /b 0"
Debug.Print fnum
Print #fnum, "if exist " & Chr(34) & Chr(34) & "C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE" & Chr(34) & Chr(34) & " (" & vbCrLf & Chr(34) & c_Main_Drive & c_Main_Folder & c_Main_Database_Folder & c_ReqDBName & Chr(34) & " " & "/x mcrEmail /cmd " & Counter & vbCrLf & "goto install" & vbCrLf & ") else if exist " & Chr(34) & Chr(34) & "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" & Chr(34) & Chr(34) & " (" & vbCrLf & Chr(34) & c_Main_Drive & c_Main_Folder & c_Main_Database_Folder & c_ReqDBName & Chr(34) & " " & "/x mcrEmail /cmd " & Counter & vbCrLf & "goto install" & vbCrLf & ")"
Write #fnum,
'use Print when you want the string without quotation marks
Print #fnum, "Batch File To Start Access and open to the submitted request record."
Close #fnum
'BuildBatchFile = "Project " & Counter & " " & VBA.Format(Date, "mm-dd-yyyy") & ".bat"
End Function
Public Function BuildBatchFile(Counter As Integer) As String
Dim fnum As Variant
Dim MyFile As String
'first set a string which contains the path to the file you want to create.
'this example creates one and stores it in the root directory
MyFile = c_Main_Drive & c_Main_Folder & c_Main_BatchFiles & "Project " & Counter & " " & Format(Date, "mm-dd-yyyy") & ".bat"
'set and open file for output
fnum = FreeFile()
Open MyFile For Output As fnum
'Batch file to open Access
Dim bfile As String
bfile = ""
bfile = bfile & "@echo off" + vbCrLf
bfile = bfile & "for /f ""tokens=2 delims==""" & " %%a in ('ftype accesshtmlfile') do set Access=%%a" + vbCrLf
bfile = bfile & "if not defined Access (" + vbCrLf
bfile = bfile & " echo No Access installation found!" + vbCrLf
bfile = bfile & " exit /b 1" + vbCrLf
bfile = bfile & ")" + vbCrLf
bfile = bfile & "echo Found Access: %Access%" + vbCrLf
bfile = bfile & "start """" %Access% ""K:\R&D Dept\Development Lab\R&D Test Request System (For testing and training)\DataBase\R&D Project Requests DB.accdb"" /x mcrEmail /cmd " & Counter & vbCrLf
bfile = bfile & "exit /b 0" + vbCrLf
bfile = bfile & vbCrLf + vbCrLf
bfile = bfile & "Sub test()" + vbCrLf
bfile = bfile & " @echo off" + vbCrLf
bfile = bfile & " setlocal" + vbCrLf
bfile = bfile & " for /f ""tokens=2 delims=="" %%a in ('ftype accesshtmlfile') do set Access=%%a" + vbCrLf
bfile = bfile & " if not defined Access (" + vbCrLf
bfile = bfile & " echo No Access installation found!" + vbCrLf
bfile = bfile & " exit /b 1" + vbCrLf
bfile = bfile & " )" + vbCrLf
bfile = bfile & " echo Found Access: %Access%" + vbCrLf
bfile = bfile & " start """" %Access% ""K:\R&D Dept\Development Lab\R&D Test Request System (For testing and training)\DataBase\R&D Project Requests DB.accdb"" /x mcrEmail /cmd " & Counter & vbCrLf
bfile = bfile & " exit /b 0" + vbCrLf
bfile = bfile & "End Sub"
Write #fnum,
'use Print when you want the string without quotation marks
'Print #fnum, "Batch File To Start Access and open to the submitted request record."
Close #fnum
End Function
Once it goes to Install, it won't return to the separate line after GOTO Install. So, Exit never runs.
> ...and have tried adding GOTO exit and then adding :exit
I think you mean "...and then adding EXIT" (without the colon). Since :EXIT by itself doesn't do anything.