Results 1 to 7 of 7
  1. #1
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149

    how to coding the checkbox in Continuous Form

    I create a Continuous Form as below
    Click image for larger version. 

Name:	check.png 
Views:	24 
Size:	43.2 KB 
ID:	47055
    When form open, it shows records, chkAll and chkBill are clear.
    Whenever i click anyone of the chkBill, it makes all chkBill to on or off.
    But the xPayAmt does not set to BalAmt accordingly, it always 0.
    I want the xPayAmt set to BalAmt when its corresponding chkBill is on and xPayAmt set to 0 when chkBill is off.


    Also if chkAll is on, all chkBill is on and all xPayAmt set to BalAmt.
    How do I code this case?
    Thanks.

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Few things to consider:

    -to make the chkBill work as you want (for individual records) it needs to be bound to a Yes\No fields in the form's recordsource; unbound controls in continuous forms will have the same value for all records.

    -once you bind the that check box to a field you can start working on your functionality; you should use the Current event of the form to load the proper value for the xPayAmt based on the value of the checkbox (you can do that by simply calling the checkbox AfterUpdate event you currently have:
    Code:
    Call chkBill_AfterUpdate
    -to make the chkAll update all the individual chkBill in each record you can use the form's recordsetclone to loop through all records in the AfterUpdate event of the chkAll checkbox:
    Code:
    Private Sub chkAll_AfterUpdate()
    Dim rs as DAO.Recordset
    
    Set rs=Me.RecordsetClone
    If rs.recordcount=0 then Exit sub
    
    Do Until rs.EOF
        rs.Edit
        rs("YourChkBillField")=Me.chkAll 'note you need to use the field not the chkBill control bound to it
        rs.Update
    rs.MoveNext
    Loop
    'Refresh the form
    Me.Refresh
    End Sub
    For future post please consider copying and pasting the actual code (using the code tags) in the forum instead of screen shots of it; it makes it easier for people helping you to edit it instead of having to type it all over again.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    Thanks Gicu.

  4. #4
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    After first click the chkAll checkbox to run the event chkAll_AfterUpdate(), it works and set all individual checkboxes to ON.
    But when I click the chkAll checkbox again, it cannot set all individual checkboxes to OFF.
    I debug to see that the rs.EOF is true, coding inside the DO LOOP have not been executed.
    I try adding rs.Close and set rs to nothing at the end of DO LOOP, but it fails.
    How can I fix it?
    Thanks

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Just reset the cursor position:
    Code:
    Private Sub chkAll_AfterUpdate()
    Dim rs as DAO.Recordset
    
    
    Set rs=Me.RecordsetClone
    If rs.recordcount=0 then Exit sub
    rs.MoveFirst  'reset to first record
    Do Until rs.EOF
        rs.Edit
        rs("YourChkBillField")=Me.chkAll 'note you need to use the field not the chkBill control bound to it
        rs.Update
    rs.MoveNext
    Loop
    rs.Close
    Set rs=Nothing
    'Refresh the form
    Me.Refresh
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    uoghk is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jan 2022
    Posts
    149
    Thanks Vlad Cucinschi.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    You're welcome!
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 5
    Last Post: 12-27-2017, 04:21 AM
  2. Write Conflict By Checkbox In Continuous Form
    By Wappervliegje in forum Access
    Replies: 9
    Last Post: 11-14-2017, 04:49 AM
  3. Replies: 3
    Last Post: 04-10-2015, 10:26 PM
  4. Continuous Form With Checkbox VB Problem
    By WhiskyLima in forum Access
    Replies: 4
    Last Post: 11-25-2013, 08:25 AM
  5. Replies: 2
    Last Post: 10-09-2012, 10:07 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