Results 1 to 7 of 7
  1. #1
    kassem is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    22

    How to find record with certain ID and update its field.

    Hi



    So i have a table called estimates and a variable called IdHolder which I use to store a number. I want to create a button that when clicked finds the record with the same ID as IDholder in the table estimates, and sets a checkbox variable called Need_Approval to true.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    in the form that shows the table records...

    Code:
    'onClick()
    me.filter = "[IDholder] = " & IdHolder
    me.filteron = true
    checkbox.value = true

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Something like this should work


    Code:
    dim rs as dao.recordset 
    set rs = currentdb.openrecordset("estimates", dbopendynaset)
    
    rs.findfirst "[ID] = " & IdHolder
    
    if rs.nomatch then
    msgbox "Unable to update the record"
    set rs = nothing
    exit sub
    end if
    
    rs.edit
    rs![Need_Approval] = -1
    rs.update
    
    
    rs.close
    set rs = nothing

  4. #4
    kassem is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    22
    ranman, How do i do this when im not on the form with the table records

  5. #5
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    Or try:
    Code:
    CurrentDb.Execute "UPDATE estimates SET [Need_Approval] = -1 WHERE [ID] = " & IdHolder

  6. #6
    kassem is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    22
    Thanks Hapm worked like a charm!

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    When using .Execute with action queries, you may want to consider employing dbfailonerror to avoid exceptions during runtime and to help ensure data integrity.

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

Similar Threads

  1. Update attachment field in existing record
    By incipientclarity in forum Programming
    Replies: 5
    Last Post: 05-28-2014, 07:20 AM
  2. Replies: 1
    Last Post: 05-26-2014, 12:39 PM
  3. Replies: 3
    Last Post: 06-06-2012, 12:45 PM
  4. Replies: 12
    Last Post: 03-14-2012, 10:54 AM
  5. Replies: 4
    Last Post: 07-22-2009, 02:33 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