Hi everyone,
I am new to access programmers and to vba.
I am storing values of pictures and the location of them in a table, this works fine!... using OpenRecordset. The problem is that when the function is called to store the information, it just keeps adding the same values of each file in the folder over and over again in a word "Duplicating" the information.
I have tried various methods using the OpenRecordset, but cannot seem to find the correct manor of applying the code.
Below is the function I have for storing the data...any help would be greatly appreciated.
:banghead:
I am new to access programmers and to vba.
I am storing values of pictures and the location of them in a table, this works fine!... using OpenRecordset. The problem is that when the function is called to store the information, it just keeps adding the same values of each file in the folder over and over again in a word "Duplicating" the information.
I have tried various methods using the OpenRecordset, but cannot seem to find the correct manor of applying the code.
Below is the function I have for storing the data...any help would be greatly appreciated.
Code:
Public Sub GetFilesNamesFromFolder(strFolderPath As String)
On Error GoTo ErrorHandler
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.folder
Dim objFile As Scripting.File
Dim objFile2 As Scripting.File
Dim strSQL As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strPrompt As String
Dim strTitle As String
Dim strTable As String
Dim intMissingCount As Integer
Dim strClientID As String
Dim fFile As String
strTable = "Document"
strClientID = Forms!Addpics!KlantNr
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strTable, dbOpenDynaset)
Set objFolder = objFSO.GetFolder(strFolderPath)
If Not objFSO.FolderExists(strFolderPath) Then
strPrompt = "Please enter a valid folder path"
strTitle = "Folder path not found"
MsgBox strPrompt, vbCritical + vbOKOnly, strTitle
GoTo ErrorHandlerExit
Else
For Each objFile In objFolder.Files
'If rst![SourceFilename] = objFile Then
'rst.FindNext (objFile)
'Else
rst.AddNew
rst![SourceFilename] = objFile.Name
rst![tDir] = objFile.path
rst![ProjectFolder] = objFolder.ParentFolder.Name
rst![ProjectSubFolder] = objFolder.Name
rst![ClientID] = strClientID
rst![DateChecked] = Date
rst.Update
Next objFile
End If
Set rst = Nothing
Set dbs = Nothing
'End If
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Sub
:banghead: