views:

100

answers:

0

I have some VBA code, which is attached to a click event of a form, running in MS Outlook 2007.

The code is dsigned to update a record in an MS Acces 2007 table, which in turn is linked offline to a SharePoint List.

It works fine for the all the list columns except for two of them.

These are:

a. A List column of Date / Time type ("Start Time") b. A list column of Lookup type ("Forum")

When attempting to update these columns, an error message occurs.

Run Time Error '-2147217916 (80040e40)

Row Handle in invalid.

The code used is below.

Any idea on how to avoid this error, or why the columns mentioned produce this error?

Sub Test2() Const DB_PATH As String = "C:\Users\GRANTHAMIA\Documents\Agenda.accdb" Dim objConnection As ADODB.Connection

Dim strSQL As String

' Set up the links to the Agenda dBase.
Set objConnection = New ADODB.Connection

'using an ACCDB file
objConnection.Provider = "Microsoft.ACE.OLEDB.12.0"
'Open a Connection to the Database
objConnection.Open DB_PATH

If objConnection.State = adStateOpen Then
    Set objRecordSetForumDetails = New ADODB.Recordset

    strSQL = "SELECT TOP 3 [ID], [Topic], [Start Time], " & _
        "[Notes], [Forum]" & _
        " FROM [Weekly Staff Agenda];"

    ' Open the recordset
    objRecordSetForumDetails.Open strSQL, objConnection, adOpenDynamic, adLockOptimistic

    With objRecordSetForumDetails
        .AddNew
        .Fields("Topic").Value = "Topic x"
        .Fields("Start Time") = #11/22/2009 10:00:00 AM# ' this produces an error
        .Fields("Forum") = 1 ' This also produces and error. This is a linked field,
                             ' linked to another sharepoint list by it's ID
        .Update
        .Close
    End With
    Set objRecordSetForumDetails = Nothing
End If

End Sub