Results 1 to 5 of 5
  1. #1
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78

    Update Current Record when Checkbox is Checked


    I am having trouble trying to update just the current record (refer to the Where statement) and I can't find anything to make it work.

    I have a Continuous form with a list of records from a table. I'm using the OnClick Event of the checkbox.

    Code:
    Private Sub bDeleted_Click()If Me.Dirty Then Me.Dirty = False
    
    
       If Me.bDeleted = True Then
    '   MsgBox Me.bDeleted.Value
    
    
            Set db = CurrentDb
                    db.Execute "Update tblEOS Set tblEOS.[bDeleted]  =" & True & _
                         " where tblEOS.[RequestID] = " & Me.RequestID, dbFailOnError
    
    
        End If
           If Me.bDeleted = False Then
    '       MsgBox Me.bDeleted.Value
            Set db = CurrentDb
                    db.Execute "Update tblEOS Set tblEOS.[bDeleted]  = " & False & _
                         " where tblEOS.[RequestID] = " & Me.RequestID, dbFailOnError
    
    
    
    
            End If
    
    
    End Sub
    Attached Thumbnails Attached Thumbnails Screenshot 2023-07-26 160443.jpg  

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,941
    Why are you concatenating True or False?, just include it in the string.
    Put the sql into a string variable, the you can debug.print it until you get it right. The use that variable in the Execute.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    If your form is bound to a table/query you don't need any code to update records. New data and edits are saved automatically.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,941
    Any time you are duplicating code, there is generally a better way?

    Code:
    Private Sub bDeleted_Click()
    Dim db As DAO.Database
    Dim strSQL As String
    
    
    'If Me.Dirty Then Me.Dirty = False
    strSQL = "Update tblEOS Set tblEOS.[bDeleted]  = " & Me.bDeleted
    strSQL = strSQL & " where tblEOS.[RequestID] = " & Me.RequestID
       
    Debug.Print strSQL
    
    
    Set db = CurrentDb
    db.Execute strSQL, dbFailOnError
    
    
    Set db = Nothing
    
    
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    I understand. I removed all the coding after "If me.dirty..." and it's working.

    Now on to Export this sucker, crossing fingers

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

Similar Threads

  1. Checkbox checked
    By brandy in forum Programming
    Replies: 2
    Last Post: 01-11-2017, 01:07 AM
  2. Checkbox Always Shows Checked
    By jo15765 in forum Forms
    Replies: 3
    Last Post: 08-16-2016, 06:58 AM
  3. If checkbox is checked allow query to run
    By burrina in forum Forms
    Replies: 14
    Last Post: 01-29-2013, 03:56 PM
  4. VBA for testing if checkbox is checked
    By rhewitt in forum Programming
    Replies: 0
    Last Post: 09-26-2012, 07:11 AM
  5. If checkbox is checked, add X to a current value
    By INeedAboutTreeFiddy in forum Programming
    Replies: 4
    Last Post: 05-30-2012, 08:17 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