Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with vba and a multivalue field

Status
Not open for further replies.

CapoStatus456

Programmer
Mar 1, 2007
1
US
So I have an access database with linked SharePoint tables. One of the columns in the table is multi-value. I'm using a recordset to create a new record and using another recordset to populate the multi-value field called "Team". However, when i run the code, I get a 3027 run-time error message ("Cannot update. Database or object is read-only"). Can someone help me out and let me know why I'm getting the error message? Here is the code:

Code:
Set db = CurrentDb()
Set rs = db.OpenRecordset("MyTable")
Set rsBT = db.OpenRecordset("SELECT Person1ID, Person2ID, Person3ID, Person4ID FROM [PeopleData] WHERE Person1ID =" & Me.PersonFormField, dbOpenDynaset)


    rs.AddNew    
        rs![Account] = Me.Account
        rs!Person1ID = Me.PersonFormField
        rs!Region = Me.Region
        rs!Request = Me.Request
        rs![Date In] = Now()
        rs!Notes = Me.Notes
   
        Set rsMV = rs.Fields("Team").Value
   
    
      For i = 0 To 3
                If Not IsNull(rsBT.Fields(i)) Then
                    rsMV.AddNew
                        rsMV.Fields(0) = rsBT.Fields(i)
                    rsMV.Update   'error happens on this line
                Else
                    Exit For
                End If
            Next i
            
    rs.Update

Thanks in advanced for the help.
 
You code looks correct. I tested this on a dummy table, and it was able to populate
Code:
Public Sub AddToMV()
  Dim Rs As DAO.Recordset
  Dim mvRS As DAO.Recordset
  Dim I As Integer
  Dim j As Integer
  Set Rs = CurrentDb.OpenRecordset("tblMV", dbOpenDynaset)
  For I = 1 To 4
   Rs.AddNew
     Set mvRS = Rs.Fields("mvField").Value
     For j = 1 To 3
       mvRS.AddNew
         mvRS.Fields(0).Value = j
       mvRS.Update
     Next j
   Rs.Update
   Rs.MoveNext
  Next I
End Sub
So that created 4 new records, with a mv field with 1,2,3 in it. Unless I am missing something your code is basically the same.

This could be an issue with the linked table, since I am not going to sharepoint. I would try adding and saving the parent record except for the MV field. Then open that record for editing, and update the MV field.

For a test see if instead of adding a new parent record, just grab an existing one and see if you can add records to the MV field
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top