Sorry, ignore last post. Misspelt Field in SQL statement.
Had to change the code slightly, was working from a bad example online. You can't trust everything you see ;)
-
Private Sub AttachScannedDocument()
-
Dim CRBApplicationRecordSet, ScannedApplicationRecordSet As Recordset
-
Dim SQL As String
-
-
SQL = "Select * From CRB Where FormNumber = '" & Me.FormNumber & "'"
-
-
' can use SQL for recordset to instantiate parent recordset
-
Set CRBApplicationRecordSet = CurrentDb.OpenRecordset(SQL)
-
-
'active edit mode
-
CRBApplicationRecordSet.Edit
-
-
' instantiate a child recordset
-
Set ScannedApplicationRecordSet = CRBApplicationRecordSet.Fields("Attachments").Value
-
-
'Add Scanned Appication
-
ScannedApplicationRecordSet.AddNew
-
ScannedApplicationRecordSet.Fields("FileData").LoadFromFile "Apollo.jpg" '"\\Universe\SharedFolders\Scans\CRBApplications\" & Me.FormNumber & ".pdf"
-
ScannedApplicationRecordSet.Update
-
-
'update parent recordset
-
CRBApplicationRecordSet.Update
-
-
Set CRBApplicationRecordSet = Nothing
-
Set ScannedApplicationRecordSet = Nothing
-
-
End Sub
-
I have two problems however.
The first time the procedure is run, it runs though with no errors. The second time I get an error message.
You cannot enter value because it duplicates and existing value in the attachment field.
How do I check to see if the value of the attachment field matches the one I'm trying to add?
More importantly the procedure does not attach the file. It seems to think that it has but it doesn't work. Any ideas where I'm going wrong here?