Hi Douglas, good to read you as always
What's the code in your batch file?
My batch file contains
CD /D "C:\Program Files\CDCheck"
START /WAIT CDCheck /CRC:MD5 "C:\Downloads" /O:"C:\Downloads
\Downloads.CRC" /SaveReport:"C:\Downloads\Downloads Report.txt"
The codes create a MS-DOS Batch File:
'Writing out a batch file (.bat or .vbs) using VBA
I Call this file called HashIt.bat
If I does not make Access wait to finish the task of the .bat file,
the results are; incomplete file .CRC and Report.txt and executing the
next VBA statement.
Please help
Thanks in advance
Regards,
Antonio Macias
My entire code is
Sub OpenWinBrowse()
Dim MyDlg As New DialogClass 'Common Dialogs Class Module for Access
and VBA
Dim vArr As Variant
Dim MyDigResponse As Integer
Dim j As Integer
Dim itemCount As Integer
Dim MyCodeSelection As Integer
Dim GetFolder As String
Dim strDrive As String
Dim FirstFolder As String
Dim LastFolder As String
Dim strItems As String
Dim TempCRCFile As String
Dim TempTXTFile As String
Dim strDir As String
Dim strVerify As String
Dim newDirectory As String
Dim ccgFF As Integer
Dim egfFF As Integer
Dim amcFF As Integer
'References:
'Microsoft DA0 3.6 Object Runtime
'Opens the Browse Dialog
With MyDlg
.TypeFile = 0 'All file Types
.TypeFile = 4 'Text Files
.DialogType = "Browse"
End With
'Show the select type of dialog selected with the properties
desired
MyDlg.Show
'Waits for the user to click a button, and returns an Integer
indicating which button
'the user clicked .DialogType = "Browse"
MyDigResponse = Len(MyDlg.ReturnFilePath)
If MyDigResponse = 0 Then
'User chose Cancel.
MsgBox "User Cancelled", vbExclamation, "Browse"
End
Else
'User Chose OK.
End If
'The name for the chosen file or directory
'Drive>:\ OR <Drive>:\Folder OR <Drive>:\Folder\Folder..
GetFolder = MyDlg.ReturnFilePath
Debug.Print "GetFolder = " & GetFolder
'Initialize New Event Split_GetFolder
'Splits The Folders in GetFolder
'Initialize Variables
vArr = Split(GetFolder, "\")
For j = 0 To UBound(vArr)
'Folders in the string separated by { \ }
If Len(vArr(j)) > 0 Then
strItems = strItems & vArr(j) & vbCr
'Debug.Print strItems
itemCount = itemCount + 1
End If
Next
Debug.Print "there are " & itemCount & " Items in this string" &
vbCr & strItems
'Manage Drive and Folders OF GetFolder
'<Drive>
strDrive = Left(vArr(0), 1)
Debug.Print "Drive = " & strDrive
'First Folder
FirstFolder = vArr(1)
Debug.Print "First Folder = " & FirstFolder
'Last Folder
LastFolder = vArr(itemCount - 1)
Debug.Print "Last Folder = " & LastFolder
'Start Event Selection_Drive_Folders
'Determine IF is <Drive>:\ OR <Drive>:\Folder OR <Drive>:\Folder
\Folder...
If itemCount = 1 Then
Debug.Print "Is <Drive>:\"
MyCodeSelection = 1
TempCRCFile = GetFolder & strDrive & " Temp" & ".CRC"
TempTXTFile = GetFolder & strDrive & " Report" & ".txt"
strDir = GetFolder & strDrive & ".CRC" 'Esto para que era?
strVerify = GetFolder & strDrive & " Verification" & ".txt"
'Esto para que era?
ElseIf itemCount = 2 Then
Debug.Print "IS <Drive>:\Folder"
MyCodeSelection = 2
TempCRCFile = GetFolder & "\" & FirstFolder & " Temp" & ".CRC"
TempTXTFile = GetFolder & "\" & FirstFolder & " Report" &
".txt"
strDir = GetFolder & "\" & FirstFolder & ".CRC" 'Esto para que
era?
strVerify = GetFolder & "\" & FirstFolder & " Verification" &
".txt" 'Esto para que era?
ElseIf itemCount >= 3 Then
Debug.Print "IS <Drive>:\Folder\Folder..."
MyCodeSelection = 3
TempCRCFile = GetFolder & "\" & strDrive & " " & FirstFolder &
" TO " & LastFolder & " Temp" & ".CRC"
TempTXTFile = GetFolder & "\" & strDrive & " " & FirstFolder &
" TO " & LastFolder & " Report" & ".txt"
strDir = GetFolder & "\" & strDrive & " " & FirstFolder & " TO
" & LastFolder & ".CRC" 'Esto para que era?
strVerify = GetFolder & "\" & strDrive & " " & FirstFolder & "
TO " & LastFolder & " Verification" & ".txt" 'Esto para que era?
Debug.Print strVerify
End If
Debug.Print "MyCodeSelection = " & MyCodeSelection
'Initialize New Event API_File_Exists
'API FileExists: Returns True of False If a File Exists
'IF FileExists = True Then Kill
If FileExists(TempCRCFile) = True Then
Debug.Print "File Exists: = True"
'<Drive>:\<Drive> Temp.CRC OR
'<Drive>\Folder\FirstFolder Temp.CRC OR
'<Drive>:\Folder\Folder...\<Drive> FirstFolder TO LastFolder
Temp.CRC
Kill (TempCRCFile)
Else
Debug.Print "File Exists: = False"
End If
If FileExists(TempTXTFile) = True Then
Debug.Print "File Exists: = True"
'<Drive>:\<Drive> Report.txt OR
'<Drive>\Folder\FirstFolder Report.txt OR
'<Drive>:\Folder\Folder...\<Drive> FirstFolder TO
LastFolder Report.txt
Kill (TempTXTFile)
Else
Debug.Print "File Exists: = False"
End If
If FileExists(strVerify) = True Then
Debug.Print "File Exists: = True"
'<Drive>:\<Drive> Report.txt OR
'<Drive>\Folder\FirstFolder Report.txt OR
'<Drive>:\Folder\Folder...\<Drive> FirstFolder TO
LastFolder Report.txt
Kill (strVerify)
Else
Debug.Print "File Exists: = False"
End If
If FileExists("C:\Program Files\Dups\Batch Files\HashIt.bat") =
True Then
Debug.Print "Batch File Exists: = True"
Kill ("C:\Program Files\Dups\Batch Files\HashIt.bat")
Else
Debug.Print "Batch File Exists: = False"
End If
'Initialize New Event Writing_out_Temporal_CRC_File
'Initialize Variables
ccgFF = FreeFile()
'Writing out a Temporal .CRC file:
'<Drive>:\<Drive> Temp.CRC OR
'<Drive>\Folder\FirstFolder Temp.CRC OR
'<Drive>:\Folder\Folder...\<Drive> FirstFolder TO LastFolder
Temp.CRC
'In order to add this file into the Hash File without user
intervention (Writing out a Temporal batch file)
Open TempCRCFile For Output As #ccgFF
Close #ccgFF ' Close file
'Initialize New Event Writing_out_Temporal_Report_TXT_File
'Initialize Variables
egfFF = FreeFile()
'Writing out a Temporal Report TXT file:
'<Drive>:\<Drive> Report.txt OR
'<Drive>\Folder\FirstFolder Report.txt OR
'<Drive>:\Folder\Folder...\<Drive> FirstFolder TO LastFolder
Report.txt
'In order to add this file into the Hash File without user
intervention (Writing out a Temporal batch file)
Open TempTXTFile For Output As #egfFF
Print #egfFF, "============ 00/00/0000 00:00:00 AM/PM
============"
Print #egfFF, "-- Results --"
Print #egfFF, "Info"
Print #egfFF, "- date: 00/00/0000"
Print #egfFF, "- process: Hash"
Print #egfFF, "- source: <Drive>:\<Folder>"
Print #egfFF, "- source volume label: Volume Name"
Print #egfFF, ' Write blank line.
Print #egfFF, "Basic statistics"
Print #egfFF, "- time elapsed: 00:00:00"
Print #egfFF, "- overall transfer [kB/s]:
000000000000,000000000000"
Print #egfFF, "- folders processed: 000000000000"
Print #egfFF, "- files processed: 00000000000000"
Print #egfFF, "- source bytes read: 000000000000 MB
(000000000000,000000000000,000000000000 bytes)"
Print #egfFF, "- source average transfer [kB/s]:
000000000000,000000000000"
Print #egfFF, "- source clean transfer [kB/s]:
000000000000,000000000000"
Print #egfFF, ' Write blank line.
Print #egfFF, "Errors"
Print #egfFF, "- errors: 000000000000"
Print #egfFF, "- warnings: 0000000000"
Print #egfFF, "- other: 0000000000000"
Print #egfFF, ' Write blank line.
Print #egfFF, "-- Messages --"
Print #egfFF, "note;hash;Hash file created (code:
0000000000000);<Drive>:\<Folder>:\File.CRC"
Print #egfFF, "note;hash;Hash file created (code:
0000000000000);<Drive>:\<Folder>:\File.CRC"
Print #egfFF, "note;hash;Hash file created (code:
0000000000000);<Drive>:\<Folder>:\File.CRC"
Close #egfFF ' Close file.
'Initialize New Event
API_Folder_Exists_And_CreateDirectory_Nested_Folders
'API Folder Exists
'Checks IF the Folder exists, IF NOT THEN create it
If FolderExists("C:\Program Files\Dups\Batch Files") = True Then
'Folder exists
Debug.Print "Folder Exists"
Else
'API CreateDirectory Nested Folders
'Folder does not exist
MsgBox "Folder Does not exits"
newDirectory = "C:\Program Files\Dups\Batch Files"
CreateNestedFoldersByPath (newDirectory)
Debug.Print "Folder Does not Exists"
End If
'Initialize New Event Writing_out_batch_file_CDCheck
'Initialize Variables
amcFF = FreeFile()
'Writing out a batch file (.bat or .vbs) using VBA
'Working and Tested Solution
'Determine IF is <Drive>:\ OR <Drive>:\Folder OR <Drive>:\Folder
\Folder...
'Please note: Very Sensitive if the user opens a file the hash
change
If MyCodeSelection = 1 Then
Open "C:\Program Files\Dups\Batch Files\HashIt.bat" For
Output As #amcFF
Print #amcFF, "CD /D " & Chr(34) & Environ("ProgramFiles")
& "\CDCheck" & Chr(34)
Print #amcFF, "START /WAIT CDCheck /CRC:MD5 " & Chr(34) &
GetFolder & Chr(34) & Chr(32) & _
"/O:" & Chr(34) & GetFolder & strDrive & ".CRC" & Chr(34)
& Chr(32) & _
"/SaveReport:" & Chr(34) & GetFolder & strDrive & "
Report" & ".txt" & Chr(34)
Close #amcFF
ElseIf MyCodeSelection = 2 Then
Open "C:\Program Files\Dups\Batch Files\HashIt.bat" For Output
As #amcFF
Print #amcFF, "CD /D " & Chr(34) & Environ("ProgramFiles")
& "\CDCheck" & Chr(34)
Print #amcFF, "START /WAIT CDCheck /CRC:MD5 " & Chr(34) &
GetFolder & Chr(34) & Chr(32) & _
"/O:" & Chr(34) & GetFolder & "\" & FirstFolder & ".CRC" &
Chr(34) & Chr(32) & _
"/SaveReport:" & Chr(34) & GetFolder & "\" & FirstFolder &
" Report" & ".txt" & Chr(34)
Close #amcFF
ElseIf MyCodeSelection = 3 Then
Open "C:\Program Files\Dups\Batch Files\HashIt.bat" For Output
As #amcFF
Print #amcFF, "CD /D " & Chr(34) & Environ("ProgramFiles")
& "\CDCheck" & Chr(34)
Print #amcFF, "START /WAIT CDCheck /CRC:MD5 " & Chr(34) &
GetFolder & Chr(34) & Chr(32) & _
"/O:" & Chr(34) & GetFolder & "\" & strDrive & " " &
FirstFolder & " TO " & LastFolder & _
".CRC" & Chr(34) & Chr(32) & _
"/SaveReport:" & Chr(34) & GetFolder & "\" & strDrive & "
" & FirstFolder & " TO " & _
LastFolder & " Report" & ".txt" & Chr(34)
Close #amcFF
End If
Debug.Print "MyCodeSelection = " & MyCodeSelection
MsgBox "Termine el Hash"
'Initialize New Event Make_Access_Wait
'Make Access wait till It is done with other application
MsgBox "Rutina ShellWait"
Call ShellWait("C:\Program Files\Dups\Batch Files\HashIt.bat")
'Implement a wait period in Access where the duration can be
'increased/decreased bychanging the constant to a corressponding
higher/lower value
MsgBox "Rutina sSleep"
Call sSleep(9000)
Next VBA statment <----
End Sub