Results 1 to 4 of 4
  1. #1
    Richard-S is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2016
    Location
    Chula Vista, California, United States
    Posts
    22

    Trying to add data to table field but records do not change - problem with movenext?

    My form is linked to a table and the code seems to work. I can see a messagebox that shows the records are being changed to the next record. That is, the names change in the messagebox. However, the created data changes for the field on the first record. The employee's name stays the same on the form's textbox during execution. The program is suppose to change each Distance field in the table. I tried making the second update for a different value (test13), but it just overwrote the first record. That is, changed test12 to test13. Code is below. Thanks for any help.



    Code:
    Private Sub Command16_Click()
    Dim Rst As DAO.Recordset
    Dim Fld As Forms
    Set Rst = CurrentDb.OpenRecordset("replacementzip")
    Dim StrInput As String
    StrInput = "test12"
    
    
    If Rst.RecordCount <> 0 Then
     Rst.MoveFirst
     Do While Not Rst.EOF
      
     txtDistance = StrInput  
    
    
      Distance = Me.txtDistance 'txtDistance does update the first record
      Me.Requery
      
      MsgBox "name and hrid " & Rst!FirstNM & ",  " & Rst!HRID & ", " & Me.Distance
     
       Rst.MoveNext  'MoveNext seems to work, that is, I can see the changes in name in messagebox, but nothing changes in the name field on the form, I don't see any subsequent employee change in the form's textboxes. 
    
    
      StrInput = "test13"  'this overwrote the first record with test13 rather than going to the second record and updating.
     Loop
    End If
    
    
    Rst.Close
    Set Rst = Nothing
    MsgBox "Finished"
    End Sub

  2. #2
    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're moving the recordset, but not the record the form is on. I'd use the edit method of the recordset to modify the underlying data.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Richard-S is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2016
    Location
    Chula Vista, California, United States
    Posts
    22

    That worked!!

    Quote Originally Posted by pbaldy View Post
    You're moving the recordset, but not the record the form is on. I'd use the edit method of the recordset to modify the underlying data.
    Thanks for your help. This was my first attempt at an automated update. I added .edit/.update process which updated the table. It's so great when something works like this did.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem.
    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. Replies: 1
    Last Post: 12-20-2015, 01:09 PM
  2. Replies: 1
    Last Post: 10-17-2013, 06:21 AM
  3. delete records when you change a field
    By fabiobarreto10 in forum Forms
    Replies: 17
    Last Post: 04-06-2012, 05:33 AM
  4. Replies: 1
    Last Post: 07-14-2011, 05:44 AM
  5. Replies: 11
    Last Post: 12-04-2010, 10:20 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