Hey all,
I have to write a code for my database,i have folder with files "pending Review" and a table with column "tblExcelLocation". when i run my database all the files from pending review folder goes to "tblExcelLocation" on a click of button.But,if the files already exists it should not insert those files and insert the rest.
For this i tried to write a code but i think i m unable to do that .Need help
THANKS
I have to write a code for my database,i have folder with files "pending Review" and a table with column "tblExcelLocation". when i run my database all the files from pending review folder goes to "tblExcelLocation" on a click of button.But,if the files already exists it should not insert those files and insert the rest.
For this i tried to write a code but i think i m unable to do that .Need help
Code:
Loop through files in folder
[COLOR="Red"]folderspec = "O:\QA Files\QC Reporting\Pending Review\"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.files
For Each fl In fc
s = s & fl.Name
s = s & vbCrLf
Next
'Debug.Print s[/COLOR]
[COLOR="red"][COLOR="Navy"]
All files from tblExcel LOcation
SQL = "SELECT * from tblExcelLocation "
Set rs = CurrentDb.OpenRecordset(SQL)
rs.MoveFirst
Do While Not rs.EOF
x = x & rs!ExcelPathLocation
x = x & vbCrLf
rs.MoveNext
Loop
'Debug.Print x[/COLOR][/COLOR]
If SOMETHING Then
[COLOR="DarkGreen"]I WANT A CONDITION HERE TO CHECK IF THE FILE ALREADY EXISTS IT SHOULD NOT UPLOAD IT AND INSERT THE REST FILES.[/COLOR]
MsgBox "do not enter"
Else
Set db = CurrentDb()
DoCmd.SetWarnings (False)
strSQl = "INSERT INTO tblExcelLocation(LotNumber,ExcelPathLocation,SearchByDate) VALUES ( " & " (' " & strLotFinalResult & "')" & ",(' " & Replace(strFullPath, "'", "''") & "'),(' " & Replace(InsertStrDb, "'", "''") & " '))"
DoCmd.RunSQL (strSQl)
DoCmd.SetWarnings (False)
db.Close
End If
End If
THANKS
Last edited: