Consulting

Results 1 to 7 of 7

Thread: next rows in continuous form doesn't update

  1. #1

    next rows in continuous form doesn't update

    Hi, I have a continuous form. I am able to update the data if the continuous form has only one entry.

    My problem is, when my query has multiple data, it only updates the 1st row of the continuous form. How can I update the other next entries?

    Existing code below doesn't works.

    Set dbforms = CurrentDb
        strSQL = "SELECT * FROM MainData WHERE [Enterprise ID] = '" & Me.txtAttUser.Value & "'"
        Set rstforms = dbforms.OpenRecordset(strSQL, dbOpenDynaset)
    
            rstforms.MoveFirst
            Do Until rstforms.EOF
            
                rstforms.Edit
                rstforms("[Employment Status]").Value = Me.txtAttStat.Value
                rstforms.Update
                
            rstforms.MoveNext
            Loop
            
        rstforms.Close   dbforms.Close

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    that would update whatever record(s) has/have an id equal to txtattuser. id's are usually unique.

    you shouldn't be using a loop to update records. use an update statement.

    currentdb.execute "update sometable set myfield='whatever' where id='blah'"

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Please explain what a "Continuous Form" is. I have never heard the term. Is it an Access VBA Term?
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    it displays multiple records vertically. like a table.

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Thanks, I don't Use Access.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    Quote Originally Posted by jonh View Post
    that would update whatever record(s) has/have an id equal to txtattuser. id's are usually unique.

    you shouldn't be using a loop to update records. use an update statement.

    currentdb.execute "update sometable set myfield='whatever' where id='blah'"
    Hi Jonh,

    I update the code to this, correct me if I'm wrong.. Getting an error: "Too few parameters. Expected 1."

        strSQL = "UPDATE MainData SET [Employment Status] = Me.txtAttStat.value WHERE [Enterprise ID] = '" & Me.txtAttUser & "'"
        dbforms.Execute (strSQL)

  7. #7
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    You missed the quotes for attstat

    "UPDATE MainData SET [Employment Status] ='" & Me.txtAttStat.value & "' WHERE [Enterprise ID] = '" & Me.txtAttUser & "'"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •