Runtime error "invalid Operation" 3219

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aditijangir
    New Member
    • May 2015
    • 17

    Runtime error "invalid Operation" 3219

    Hi Friends,

    I am a newbie in MS ACCESS. I am using A2010 Version. What I am expecting my code to do is: Compare the field of the table and update other field in the same row.

    My code will make sense better htan words :)

    Code:
    Dim zDB As DAO.Database
         Dim zRS As DAO.Recordset
         Dim zSQL As String
         '
         zSQL = "UPDATE AddUser SET [Password]='" & Pwd & "' WHERE AddUser.EmployeeId='" & User & "';"
        
         '
         'See here is where I set the pointer to the current
         'database only once
         Set zDB = CurrentDb
         '
         'using recordsets...
        [B]Set zRS = zDB.OpenRecordset(zSQL, dbOpenSnapshot)  'getting ERROR in this line
    [/B]     '
         '
         zRS.close
         If Not zRS Is Nothing Then Set zRS = Nothing
         If Not zDB Is Nothing Then Set zDB = Nothing
    Need urgent help. Please provide valuable feedback.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    The OpenRecordset method can't be used on UPDATE queries as it doesn't return any records. Instead you would do the following.
    Code:
    zDB.Execute zSQL, dbFailOnError
    You can get rid of the zRS declaration in line 2 and all other lines that reference it.

    Comment

    • aditijangir
      New Member
      • May 2015
      • 17

      #3
      Thank you so much for your reply.

      System is still throwing an error after I made the provided changes.

      ERROR: 128
      Datatype mismatch

      Note: EmployeeId is an Primary Key with Numeric datatype

      Have a look to the code:

      Code:
      Dim zDB As DAO.Database
        '  Dim zRS As DAO.Recordset
           Dim zSQL As String
      
      Set zDB = CurrentDb
      zSQL = "UPDATE AddUser SET [Password]='" & Pwd & "' WHERE AddUser.EmployeeId='" & User & "';"
           zDB.Execute zSQL, dbFailOnError
        
          ' zRS.close
          ' If Not zRS Is Nothing Then Set zRS = Nothing
           If Not zDB Is Nothing Then Set zDB = Nothing
      Please provide your feedback.
      Last edited by Rabbit; May 13 '15, 05:31 PM. Reason: Fixed code tags

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        "Note: EmployeeId is an Primary Key with Numeric datatype"

        This is the key to your problem. You are passing the User as a string because of the single quotes. Make your zSQL variable WHERE clause be the following.
        Code:
        WHERE AddUser.EmployeeId=" & User & ";"

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          To provide context: Check for existing EmployeeId in the table and then update password in same table- post#8
          (I also answered the reason for Error-3219 in this post :) )
          Last edited by zmbd; May 13 '15, 10:09 PM.

          Comment

          • aditijangir
            New Member
            • May 2015
            • 17

            #6
            Oh. Small mistake lead me in trouble :P

            Thank you so much seth. I am really thankful for solving my problem. :D

            Comment

            • aditijangir
              New Member
              • May 2015
              • 17

              #7
              Thank you zmdb for your wonderful help . :)

              Comment

              Working...