Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    ZachAtaiyan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    41
    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


  2. #17
    ZachAtaiyan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    41
    Awesome! I will give that a shot then!

  3. #18
    ZachAtaiyan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    41
    IT WORKED!

    Thanks again to the both of you. Communities like this are great.

    Here is the final code section from the 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
        Dim Path As String
        
        'Captures end boundary timestamp
        Time2 = Now
        
        'Defining incremental operation
        i = 1
        Path = TempVars!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(Path & "\" & 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 Path & "\" & 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

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Application-defined or object-defined error
    By SYFYLADY in forum Access
    Replies: 4
    Last Post: 03-05-2014, 05:25 PM
  2. Replies: 3
    Last Post: 11-12-2013, 04:13 PM
  3. user-defined type not defined
    By markjkubicki in forum Programming
    Replies: 3
    Last Post: 05-09-2013, 05:15 PM
  4. Replies: 20
    Last Post: 06-04-2012, 11:48 AM
  5. Application-defined or object-defined error
    By hawkins in forum Access
    Replies: 6
    Last Post: 07-01-2011, 01:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums