将Sharepoint表数据复制到Access表 - 错误3421

时间:2014-04-29 20:01:11

标签: vba ms-access sharepoint access-vba type-conversion

我正在使用Access 2007和Sharepoint 3.0。我在我的数据库中创建了一个Sharepoint List。使用VBA(下面)我试图从Sharepoint列表中的字段“复制”数据,以“粘贴”到我的Access Db中的另一个字段。

代码成功运行到'粘贴'部分。我已经确认使用debug.print(代码成功复制Sharpoint List数据)一切都很好但是'粘贴'时会弹出错误3421。

提前感谢您的帮助!

Dim rs_first As DAO.Recordset
Dim rs_end As DAO.Recordset
Dim tbl_start As String
Dim tbl_end As String

Dim rep As Variant
Dim proj As Variant
Dim hrs As Integer
Dim s_dt As Date
Dim e_dt As Date

tbl_start = "TEST_Resource" '<-- ***This is the Sharepoint List***
tbl_end = "MiddleTable"

Set rs_start = CurrentDb.OpenRecordset(tbl_start) 
Set rs_end = CurrentDb.OpenRecordset(tbl_end)

proj = rs_start.Fields("Projected Task")
rep = rs_start.Fields("Associate Name")
hrs = rs_start.Fields("Projected Hours")
s_dt = rs_start.Fields("Start Date")
e_dt = rs_start.Fields("End Date")

'Adding a Record to Table
        With rs_end
            .AddNew
                .Fields("ProjectName") = proj '<---***Error 3421****
                .Fields("Employee") = rep
                .Fields("Hours") = hrs
                .Fields("Week") = s_dt
            .Update
        End With

1 个答案:

答案 0 :(得分:1)

这是数据类型转换错误。您需要确保rs_start.Fields("Projected Task")数据类型与rs_end.Fields("ProjectName")相同。检查每个字段的Type。如果它们不相同,则需要进行相应的投射。