Thank you, I realize what I posted is really messy... I actually just scrapped the whole thing and rewrote it. here:
Now when I execute the command, nothing happens. Any ideas? The last error I was getting was because I was referencing an object that I hadn't created yet. Thanks!
Code:
Private Sub Command33_Click()
On Error GoTo Err_AddImage
Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Dim FileName As String
Dim Directory As String
Dim FSO As Object
Dim Time1 As Date
Dim Time2 As Date
Set db = CurrentDb
Set rsParent = Me.Recordset
rsParent.Edit
Set rsChild = rsParent.Fields("Field1").Value
'File Source Folder
Directory = "C:\Users\zfataiyan\Desktop\TESTFOLDER"
If Right(Directory, 1) <> "\" Then
Directory = Directory & "\"
End If
'Search for all files in the directory with an .jpg* file type.
FileName = Dir(Directory, vbNormal)
'Use Do loop to add files created after Time1 and Before Time2.
Set FSO = CreateObject("Scripting.FileSystemObject")
'''''Loop Time''''''--------------------------------------------
''''''''''''''''''''
Do While FileName <> ""
OpenFile = Directory & FileName
If FSO.GetFile(Directory & FileName).DateCreated >= Time1 And FSO.GetFile(Directory & FileName).DateCreated <= Time2 Then
'load file into Field1
rsChild.AddNew
rsChild.Fields("FileData").LoadFromFile FileName
rsChild.Update
rsParent.Update
End If
Exit_AddImage:
FileName = Dir()
OpenFile = ""
Loop
'''''''''''''''''''''---------------------------------------------
Set rsChild = Nothing
Set rsParent = Nothing
Exit Sub
Err_AddImage:
If Err = 3820 Then
MsgBox ("File already part of the multi-valued field!")
Resume Next
Else
MsgBox "Some Other Error occured!", Err.Number, Err.Description
Resume Exit_AddImage
End If
End Sub