So I have implemented TempVars and it pulls the value exactly how I want it to. However I am still getting a run-time error 53 at the line "FileTime = FileDateTime(StrFile)". Any ideaas why? Here is my code:
1st subform:
Code:
Option Compare Database
Option Explicit
Private Sub SelectFolder_Click()
Dim strFolderName As String
strFolderName = BrowseFolder("Choose Folder For Image Attachments")
If Len(strFolderName) > 0 Then
TempVars.Add "RootFolder", strFolderName
End If
End Sub
2nd Subform
Code:
Option Compare Database
Option Explicit
Dim Time1 As Date
Dim Time2 As Date
Private Sub Command27_Click()
'Image Capture Button - Utilizes Panasonic FZ-G1's Camera utility to capture images and store them to each record.
'Each photo is approx 149kb.
'Open the Camera Utility
'Call Shell("C:\Program Files (x86)\Panasonic\PCam\PCam.exe", vbNormalFocus)
Call Shell("C:\Windows\System32\mspaint.exe", vbNormalFocus)
'Captures initial boundary timestamp
Time1 = Now
End Sub
Private Sub Command33_Click()
'Calls Subroutine that attaches images
Call LoopThroughFiles
End Sub
'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 i As String
'Captures end boundary timestamp
Time2 = Now
'Defining incremental operation
i = 1
'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(TempVars!RootFolder & "\*.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("Field" & i).Value 'This code designates the target for the attachment within the form, varies for Field1 and Field2
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
If i < 2 Then
i = i + 1 'Increments i for the next pass through if statement
End If
End If
StrFile = Dir 'This code calls the next file in the folder to determine if it should be attached
Loop
End Sub