So I have been trying to incorporate this, but It does not seem to work for this application. I know the rest of the code is correct because If I assign "C:\Users\bob\pictures\" to RootFolder2, it works perfectly. I inserted a message box to show what RootFolder2 was assigned to and it shows the destination I specified in the first form. Any ideas why this isn't working?
Overall Form:
Code:
Option Compare Database
Public RootFolder As String
1st form where folder is specified:
Code:
Option Compare Database
Public RootFolder As String
Private Sub SelectFolder_Click()
Dim strFolderName As String
strFolderName = BrowseFolder("Choose Folder For Image Attachments")
If Len(strFolderName) > 0 Then
Forms!MainAssessmentForm.RootFolder = strFolderName
End If
End Sub
2nd form where destination folder is used to import files:
Code:
'This sub-routine searches through a user-designated directory for every file that was created during a given time interval.
'Each file within the designated folder is run through the sub routine.
Sub LoopThroughFiles()
Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Dim StrFile As String
Dim FileTime As Date
Dim RootFolder2 As String
'Captures end boundary timestamp
Time2 = Now
RootFolder2 = Forms!MainAssessmentForm.RootFolder
'This section of code is used to search through the folder designated by the user in the introduction tab
'to find files that were created between Time1 and Time2.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
StrFile = Dir(RootFolder2 & "*.jpg*")
Do While Len(StrFile) > 0
FileTime = FileDateTime(StrFile) 'This code determines the time that each image was created.
If FileTime >= Time1 And FileTime <= Time2 Then
Set db = CurrentDb
Set rsParent = Me.Recordset
rsParent.Edit
Set rsChild = rsParent.Fields("Field1").Value 'This code designates the target for the attachment within the form
rsChild.AddNew
rsChild.Fields("FileData").LoadFromFile StrFile 'This code attaches the file to the target destination
rsChild.Update
rsParent.Update
Exit_AddImage:
Set rsChild = Nothing
Set rsParent = Nothing
End If
StrFile = Dir 'This code calls the next file in the folder to determine if it should be attached
Loop
End Sub