Results 1 to 8 of 8
  1. #1
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76

    subform data update via button

    I am trying to get a button to update the records in a subform via the data in a parent form field. The below code works but only on the first record of the subform and I need the code to update all the subform records. Any help on what I am missing will be greatly appreciated.



    Dim rs As DAO.Recordset
    Set rs = Me.[Tbl CheckExpenseType subform].Form.RecordsetClone
    With rs
    .MoveFirst
    Do While Not .EOF
    .Edit
    [Tbl CheckExpenseType subform]!Number = [Number]
    .Update
    .MoveNext
    Loop
    End With
    Set rs = Nothing

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Your subform container is named tblcheckexpensetype.....?

  3. #3
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    yes that is the correct name.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Just after "With rs" place


    dim intCount as integer
    intcount = .recordcount

    msgbox "There are only " & intcount & " records in the recordset clone."

  5. #5
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    Thanks for the response.
    The code you added returns the correct number of records.
    I still have the problem that only the first record updates to the new value. It looks like the below line of code works but it is not looping in the "do while"
    [Tbl CheckExpenseType subform]!Number = [Number]




  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    That was the only thing that was suspect. You mentioned the first record was getting updated so thought I would check that first.

    !Number = Me.Number

    This will update the field named "Number" that resides within the recordset using the value that is present in the Main form's "Current" record.

  7. #7
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    Perfect.
    Thanks!

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    No problem. You don't have to use With and End With.

    For instance, without the with thingy.....

    rst![FieldName] = strFieldValue

    strFieldValue = rst![FieldName]

    and

    rst.Update

    rst.MoveNext

    etc


    Might help you keep track of where the recordset is. Then, after you get tired of typing the recordset name over and over, go back to With

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

Similar Threads

  1. Form update with new data in sub-subform.
    By Degs29 in forum Programming
    Replies: 8
    Last Post: 06-21-2013, 01:56 PM
  2. Replies: 8
    Last Post: 05-30-2013, 05:06 PM
  3. Replies: 13
    Last Post: 02-04-2013, 04:08 AM
  4. Replies: 8
    Last Post: 11-08-2011, 05:11 AM
  5. Replies: 3
    Last Post: 07-29-2011, 09:30 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