Results 1 to 7 of 7
  1. #1
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42

    Recordset to update a table

    I am trying to update a table using a recordset but I am having no luck.
    There are 5 columns in the table that affect what I am trying to do.
    They are: ConfCode, CC_B, CC_D, CC_ND, and CC_V. The first is
    type Text and the others are Yes/No types. See the attached snippet
    of the table.

    For each record with a ConfCode of "D", I want the field CC_C to be
    checked, i.e., True or Yes. Similarly with a ConfCode of "BVD", CC_B
    to be checked, and so on.

    The code runs without error, but the underlying table does not show
    any check marks, even after clicking on "Refresh All".



    Any assisttance appreciated.

    Here is the code:


    Dim myConnection As ADODB.Connection
    Dim rst As New ADODB.Recordset
    DoCmd.SetWarnings True
    DoCmd.Echo True
    Set myConnection = CurrentProject.Connection
    rst.ActiveConnection = myConnection
    rst.Open "SELECT * FROM [Individual Donor Table]"


    'Check to see if the recordset actually contains rows
    If Not (rst.EOF And rst.BOF) Then
    rst.MoveFirst 'Unnecessary in this case, but still a good habit
    Do Until rst.EOF = True
    Select Case ConfCode
    Case ConfCode = "D"
    CC_D = True
    Case ConfCode = "ND"
    CC_ND = True
    Case ConfCode = "BVD"
    CC_B = True
    Case ConfCode = "V"
    CC_V = True
    End Select


    'Move to the next record. Don't ever forget to do this.
    rst.MoveNext
    Loop
    Else
    MsgBox "There are no records in the recordset."
    End If


    MsgBox "Finished looping through records."


    rst.Close 'Close the recordset
    Set rst = Nothing 'Clean up
    Attached Files Attached Files

  2. #2
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42
    Correction: CC_C should read CC_D.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You aren't referring to the recordset. It would look like:

    rst.Edit
    rst!CC_D = True
    rst.Update

    That said, an update query would be more efficient. That said, I probably wouldn't have the checkbox fields, I'd have a related table that linked the conference code to the appropriate code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42
    Tried the changes but I get the following message error on rst.Edit:

    "Method or data member not found".

    Can you elaborate more on the second part of your response?

    John

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I don't normally use ADO recordsets (I use DAO). Perhaps they don't have an Edit method. Try just the line setting a value:

    rst!CC_D = True
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    john134 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2014
    Posts
    42
    I switched to DAO and used your suggested edits in your first reply and everything works.

    Thank you,

    John

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help John.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. recordset won't update
    By charlieb in forum Access
    Replies: 3
    Last Post: 04-13-2015, 05:56 PM
  2. VBA Recordset.Update doesn' run with args ...
    By fluppe in forum Programming
    Replies: 4
    Last Post: 07-15-2014, 01:18 PM
  3. Update recordset - 'Not responding'
    By tariq1 in forum Programming
    Replies: 2
    Last Post: 08-11-2012, 11:33 AM
  4. Update Query?? or RecordSet??
    By bbrazeau in forum Queries
    Replies: 2
    Last Post: 01-13-2012, 08:44 AM
  5. Update combo box from recordset
    By kc1 in forum Access
    Replies: 5
    Last Post: 12-12-2011, 06:14 PM

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