Ms Access 2007 and Ms Sharepoint 2007 (Issue with Attachments)

S

scott

Hi,

I'm running MS Office Enterprise 2007 SP2, MS Sharepoint 2007 SP2 on
machines running Windows 2003 Enterprise.

My application is simple. I'm linked to several Sharepoint tables (or
lists) in a project via MS Access. I have a large table in Access that has
attachments and I'm trying to post the attachments to specific records in the
Sharepoint List.

In all my attempt I receive an error.

Run-Time error '3001'

Invalid Argument.


I've also used the code in this example, and get the same problem.

http://blogs.msdn.com/access/archive/2008/07/25/adding-attachments-from-a-folder.aspx


Now, I do get a different result if instead of saving the attachment to a
file on Sharepoint I save it locally to MS Access file; it works everytime
and the code is correct.

So what is up with Sharepoint and why is it different? And how can the code
be changed to work correctly in this environment?





---------- Code -------------

Dim rstParent As DAO.Recordset2
Dim rstChild As DAO.Recordset
Dim fldAttach As DAO.Field2
Dim Guiderst as DAO.recordset

' Guiderst is my table that I need to store my attachements.
' in Sharepoint.

' Attachments is my field in Sharepoint to save the attachment
' and I have a like name in the file that contains the actual
attachements

' get the attachment recordset and FileData field to contain
the file

Set rstChild = Guiderst.Fields("Attachments").Value
Set fldAttach = rstChild.Fields("FileData")

' add the attachment to the attachment field
rstChild.AddNew

' I've tried adding the fields data that has the attachment and
' letting it equal the data and also also tried reading it in
as in the
' example below.

fldAttach.LoadFromFile "C:\tmp\" & "4130X.pdf"
rstChild.Update
 
S

scott

Hello Microsoft,

Is anyone able to help on this issue? Are there anyone from MS interested
in lending a hand?
 
S

S. Kosciolek

I ran into exactly this problem this morning... There's not a bit of help anywhere on the web, but I figured it out. Perhaps what I did will help you.

One of the sites I visited suggested that DAO was too outdated to do this, and that switching to ADO would do the trick. It does, but not as straightforward as you might like

Anyway, here's the code. Hope it helps

Private Sub Command0_Click(
Dim rstFrom As ADODB.Recordse
Dim rstTo As ADODB.Recordse
Dim rstMVF As ADODB.Recordse
Dim rstMVT As ADODB.Recordse

Set rstFrom = New ADODB.Recordse
' table1 is where my attachments are currently store
rstFrom.Open "select * from table1", CurrentProject.Connection, adOpenDynamic, adLockOptimisti

Set rstTo = New ADODB.Recordse
' no_spend is the table where I am putting them
rstTo_Open "No_Spend", CurrentProject.Connection, adOpenDynamic, adLockOptimisti

Do While rstFrom.EOF = Fals
rstTo.AddNe
'these next three lines are other data fields, not part of the attachments
rstTo!Month = rstFrom![mth
rstTo!Year = rstFrom![yr
rstTo![Employee ID] = rstFrom![Employeeid
'you do need something in the row... you cannot attach to a empty row.
rstTo.Updat
Set rstMVF = rstFrom!Attach.Valu
Set rstMVT = rstTo!Attachments.Valu

Do While rstMVF.EOF = Fals
Dim url As Strin
'both the filename and the URL need to be proper URL's
url = "https://<put your URL here>/Lists/No_Spend/Attachments/" & rstTo.Fields(0) & "/" & rstMVF!Filenam

rstMVT.AddNe
rstMVT!FileData = rstMVF!FileDat
rstMVT!FileFlags = rstMVF!FileFlag
rstMVT!Filename = url ' rstMVF!Filenam
rstMVT!FileTimeStamp = rstMVF!FileTimeStam
rstMVT!FileType = rstMVF!FileTyp
rstMVT!FileURL = url ' rstMVF!FileUR
rstMVT.Updat
rstMVF.MoveNex
Loo

Set rstMVF = Nothin
Set rstMVT = Nothin

rstTo.Updat
rstFrom.MoveNex

Loo

rstFrom.Clos
rstTo.Clos
End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top