Hello,
I have been working on calling a batch file from with a Access database report - using VBA
I completed this successfully, but now want to convert the script to run within the VBA code itself (this would help avoid the possibility of the batch file getting deleted)
Batch script - called from VB code with
Call shell(Environ$("COMSPEC") & " /c c:\Access\Rob\split_File.bat BTN", vbNormalFocus) ' run script to split the TT-NONSTG file into separate files
Ive worked out most of the commands for VB apart from the splitting of the files
VB code
but im stumped as to how to code this
I have been working on calling a batch file from with a Access database report - using VBA
I completed this successfully, but now want to convert the script to run within the VBA code itself (this would help avoid the possibility of the batch file getting deleted)
Batch script - called from VB code with
Call shell(Environ$("COMSPEC") & " /c c:\Access\Rob\split_File.bat BTN", vbNormalFocus) ' run script to split the TT-NONSTG file into separate files
Code:
@echo off
cd c:\Access\Rob\TTFILS\%1
del TT-NONSTG-*.bak TT-NONSTG.old
ren TT-NONSTG-*.txt TT-NONSTG-*.bak
for /f "tokens=1-16 delims=," %%d in ('type "TT-NONSTG.txt"') do (
>>"TT-NONSTG-%%g.txt" echo(%%d,%%e,%%f,%%g,%%h,%%i,%%j,%%k,%%l,%%m,%%n,%%o,%%p
)
move /y TT-NONSTG.txt TT-NONSTG.old
Ive worked out most of the commands for VB apart from the splitting of the files
VB code
Code:
Sub SplitFiles()
Dim DelVal As Variant
' delete old .bak files
'
ChDir "c:\Access\Rob\TTFILS\BTN" 'Change folder to desired folder
DelVal = Dir("*.bak") 'Get first file in folder
Do While Len(Nz(RetVal)) > 0 'Delete until no more files
Kill PATHTOTTFILEbtn & DelVal
RetVal = Dir() 'Get next file to rename
Loop
' delete old .old file
'
Kill PATHTOTTFILEbtn & "TT-NONSTG.old"
' rename old .txt files as .bak
'
Dim RetVal As Variant
RetVal = Dir("*.txt") 'Get first file in folder
Do While Len(Nz(RetVal)) > 0 'Rename until no more files
Name RetVal As Left(RetVal, Len(RetVal) - 3) & "bak" 'Rename
RetVal = Dir() 'Get next file to rename
Loop
' split the original file
'
for /f "tokens=1-16 delims=," %%d in ('type "TT-NONSTG.txt"') do (
>>"TT-NONSTG-%%g.txt" echo(%%d,%%e,%%f,%%g,%%h,%%i,%%j,%%k,%%l,%%m,%%n,%%o,%%p
)
' rename non split file to .old
'
Name PATHTOTTFILEbtn & "TT-NONSTG.txt" As PATHTOTTFILEbtn & "TT-NONSTG.old"
End Sub
but im stumped as to how to code this