Results 1 to 5 of 5
  1. #1
    WhiskyLima is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2013
    Location
    UK
    Posts
    32

    Continuous Form With Checkbox VB Problem

    Hi All! So Im having a VB related issue with a continuous form. I want to go through each record in a form when it loads and check if a checkbox for each record [depositPaid] is checked or not. If it is then I want to add the amount in the box [Deposit] to the total in the box [totalSpend]. What I'm having a problem is the code is only picking up on the checkbox in the first record and is basing the rest of its response on that single checkbox.



    To simplify things for now I have written this code below to message 'check' on screen each time it reaches a record with the check box ticked. Any ideas where i'm going wrong here?

    Code:
    Private Sub Form_Load()
    Dim rst As Recordset
    Set rst = Form.RecordsetClone
         rst.MoveFirst
         While Not rst.EOF
            If depositPaid = -1 Then
            MsgBox ("Check")
            End If
         rst.MoveNext
         Wend
    End Sub
    Appreciate the help guys!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by WhiskyLima View Post
    Hi All! .....the code is only picking up on the checkbox in the first record and is basing the rest of its response on that single checkbox.
    Sounds like an unbound checkbox. An unbound control will only work for the current record. For instance, you can place a command button on a continuous form. When a user clicks it, the focus will be on that specific record. All VBA will be associated with the record that has focus.

  3. #3
    WhiskyLima is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2013
    Location
    UK
    Posts
    32
    Its data control source is set to a field called isDepositPaid in the same table the rest of the continuous form pulls its information from. This is because I want it to save the data in this box in the related record for later use. Should I be trying to take the information from the table itself? If so how would I go about this?

  4. #4
    WhiskyLima is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2013
    Location
    UK
    Posts
    32
    I have figured out the problem, It seems a RecordSetClone will clone the data but obviously not the actual controls in the continuous form. Im not sure why exactly this works but here is new code:

    Code:
    Private Sub Form_Load()
    Dim rst As Recordset
    Set rst = Form.Recordset
         rst.MoveFirst
         While Not rst.EOF
            
            If depositPaid = -1 Then
                MsgBox ("Check")
            End If
            
         rst.MoveNext
         Wend
    End Sub
    Here the only change needed was the line

    Code:
    Set rst = Form.RecordsetClone
    Which was changed to

    Code:
    Set rst = Form.Recordset
    Thank you for your help however, it does help me to think outside of the box a little with a different perspective.

    Much Appreciated

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by WhiskyLima View Post
    Which was changed to

    Code:
    Set rst = Form.Recordset
    That is very interesting. You say the checkbox is bound to the form's recordset. Maybe some of the checkboxes were Null. I definitely am curious how this code you posted behaves. Glad you got a solution and thanks for posting.

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

Similar Threads

  1. Checkbox problem if Yes or No
    By Amen in forum Access
    Replies: 3
    Last Post: 09-23-2013, 11:54 PM
  2. Yet another continuous form problem...
    By DarrenUD in forum Forms
    Replies: 3
    Last Post: 04-02-2013, 11:33 AM
  3. Continuous Form Totals Problem
    By burrina in forum Forms
    Replies: 2
    Last Post: 02-22-2013, 02:35 AM
  4. Problem with my checkbox vba code
    By wrkadri in forum Programming
    Replies: 2
    Last Post: 12-13-2012, 02:12 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