Runtime Error 3001 on attachments field

nagendra123

New member
Local time
Today, 19:57
Joined
Nov 28, 2007
Messages
3
Hi,
I have this issue bothering me for quite sometime and i am totally exhausted trying to find information on this error Runtime Error 3001, invalid arguments on internet.
Here is what i am trying to do
1. I have an MSAccess 2007 database table with an attachment field in it.
2. I am trying to attach .pdf file to each of the records (300 records) from the file in my local hard disk.
3. I am pasting my code to show how it looks.

Dim strDB As String

' Initialize string to database path.
Const strConPathToSamples = "D:\test\Sharepoint\Nags\Nags\TestProject\TestProject"

strDB = strConPathToSamples & "Incoming Documents_26thNov_Backup.accdb"
Dim db As DAO.Database
Set db = CurrentDb
Dim rsattach As DAO.Recordset
Dim rsPictures As DAO.Recordset
Set rsattach = db.OpenRecordset("SharedDocslist_21stNov")
Dim strFile, strNewFileName
Dim fsoSysObj As Scripting.FileSystemObject
Set fsoSysObj = New Scripting.FileSystemObject
Dim fdrFolder As Scripting.Folder
Dim i
Dim filFile As Scripting.File
Dim fldAttach As DAO.Field2

i = 0
Set fdrFolder = fsoSysObj.GetFolder("D:\Nags\Test")

While Not rsattach.EOF
rsattach.Edit
' Instantiate the child recordset.
Set rsPictures = rsattach.Fields("Attachments").Value

If rsPictures.RecordCount = 0 Then
i = i + 1
rsPictures.AddNew
strFileName = Dir("D:\Nags\test\*.*" & i)
Set filFile = fsoSysObj.GetFile("D:\Nags\test\" & strFileName)
filFile.Move ("D:\Nags\Test\" & Left(filFile.Name, InStrRev(filFile.Name, "_") - 1))
'rsPictures.Fields("FileData").LoadFromFile (filFile.Path)

'End If
' strFileName = rsFileAttach.Fields("FileName").Value
' Set rstChild = rsAddNew.Fields("Attachments").Value ' the .Value for a complex field returns the underlying Recordset.
' rstChild.AddNew

Set fldAttach = rsPictures.Fields("FileData") ' set the DAO.Field2 object to the field that holds the binary data.
fldAttach.LoadFromFile (filFile.Path) ' store the file's contents in the new row. .......This is where i am getting the error.....
rsPictures.Update
rsattach.Update
End If
' Loop through the attachments.

Set rsPictures = Nothing
rsattach.MoveNext
Wend

Set rsattach = Nothing
Set db = Nothing
'appAccess.CloseCurrentDatabase
Set appAccess = Nothing

I am getting error while trying to execute LoadfromFile call in teh above code.

Please help me out if anyone has recieved this error and if they resolved it....A large task is looming on my head and i am running out of ideas to fix it...

Regards
Nagendra
 
This is just a question as I haven't tested this feature in 2007 (I wouldn't store attachments in an Access database if you paid me to do so as there are too many things that can go wrong and it is almost as easy to just store the path and use that when needed). But, have you tried replacing

fldAttach.LoadFromFile (filFile.Path)

with an explicit path to make sure that is working?

fldAttach.LoadFromFile ("C:\Temp\MyTest.pdf")

Also, I would look to see if you get an actual valid path from strFileName because I'm not seeing where you are going to have one with

*.* & i
 
Runtime Error 3001 on attachments field Reply to Thread

first of all thanks bob for replying to this question.
Ok let me answer your questions first.
The data i am storing in Access database is only temporary and ones i get the attachments in the DB, i am going to bulk transfer them to a sharepoint site using export to feature in MSAccess. I did this before and it worked.
I have tried using explicit path and it threw me the same error as before.
strFileName definitely returns me the name of the file and also i am using filesystem object to retrieve the filepath and i have debugged teh code and tested it already.
Only problem is still this run time error.
Hope i answered your questions Bob.....
 
Any more Suggestions

Any more suggestions guys. I am waiting for an answer from any of you experts sitting out there. Please help me.
 

Users who are viewing this thread

Back
Top Bottom