Results 1 to 3 of 3
  1. #1
    Datech is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    40

    Problem Changing Value of single field in recordset in VB

    I'm trying to cycle through the records in a recordset, then set the value of one of the fields on one of the records to True, False, or Undefined (all text, not Boolean). In testing this, I've got to the point where there should only be one record in the recordset. Here's the code:

    Code:
    Do Until rs2.EOF
          If Table_RecordCount(rs2) = 1 Then 
                rs2.Fields(11).Value = "True"
    Table_RecordCount is a function I got from pbaldy's site that counts the number of records in the recordset. I get an error on the third line, where I'm trying to set the 11th field's value to "True". The error is Run-time error '91': Object variable or With block variable not set.

    The 11th field exists, and I thought this was the appropriate syntax for changing a value like this. I don't know what variable I would need to define though. Any help?

  2. #2
    Datech is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    40
    Did some more testing, and I think it's actually the Table_RecordCount function. Here's the function I'm using:
    Code:
    Public Function Table_RecordCount(rs As DAO.Recordset) As Long    'Dim rs As DAO.Recordset
        
        'Set rs = CurrentDb.OpenRecordset(sTable)
        
        If Not (rs.EOF) Then
            rs.MoveLast
            Table_RecordCount = rs.RecordCount
        End If
        
        Set rs = Nothing
    End Function
    As you can see from the commented lines, this initially read in a table and performed the recordcount. Did I modify the function wrong? I want it to read in a recordset that I've already defined and give me the count.

  3. #3
    akrylik is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    47
    Maybe change the line :

    rs2.Fields(11).Value = "True"

    to either

    rs2(11).Value = True or rs2(11) = "True"

    rs2.Fields(11).Value = "True"to

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 16
    Last Post: 04-11-2012, 10:56 AM
  2. Recordset problem(s)
    By bbrazeau in forum Programming
    Replies: 14
    Last Post: 10-19-2011, 12:41 PM
  3. Replies: 1
    Last Post: 08-19-2011, 02:53 PM
  4. Recordset Findfirst Problem
    By ColPat in forum Programming
    Replies: 6
    Last Post: 07-22-2010, 04:34 AM
  5. Replies: 1
    Last Post: 11-13-2009, 03:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums