Results 1 to 10 of 10
  1. #1
    pwdpwd is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    UK - Barnsley
    Posts
    6

    Counting only 'checked' Yes/No fields on a

    I have a continuous form in 2007 that has a text field and a yes/no check box, bound to a query. The user can select as many of the check boxes as required; the functionality works fine, but I want to build in a check before they exit the form that they have selected at least one.



    I have worked out a way to count the total of the Yes/No fields on the form, but how do I count only the fields that have been checked?

    I have messed around with GetDatainField, but I have had no luck.

    Any help would be gratefully appreciated

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    What are you using to count the Yes/No fields? The value for the check-box when checked is -1. Could you only count the Yes/No field if it was a -1?

  3. #3
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by pwdpwd View Post
    I have a continuous form in 2007 that has a text field and a yes/no check box, bound to a query. The user can select as many of the check boxes as required; the functionality works fine, but I want to build in a check before they exit the form that they have selected at least one.
    my 2 cents:

    a query is automatically saved by form updates when you change from record to record, right?? Well, why not, on exit of the form, simply use DCOUNT() and check the query itself for the number of -1's you have??

  4. #4
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    That's why they pay you the big bucks Adam!

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by jgelpi16 View Post
    That's why they pay you the big bucks Adam!
    That's right, bud! I'm the end all be all of human existence. NOT.

  6. #6
    pwdpwd is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    UK - Barnsley
    Posts
    6
    Hi Guys - Thanks very much for the help so far, but the VB that I'm using gives erratic results (which I've no doubt is my fault!).

    The following is the current state of the code for the <Exit> form button:

    Code:
    Private Sub Command12_Click()
    Dim subavail As Integer
    Let subavail = DCount("*", "qry_subjectsavailable")
    If subavail = 0 Then
        Dialog.RichBox "You have not selected a Subject!", vbExclamation, "No Subject Selected!", , , ButtonDelay:=1
        Exit Sub
    Else
        DoCmd.Close
        DoCmd.OpenForm "frmSubject"
    End If
    End Sub
    I've also used a fuller version of DCount - =DCount("[subjectavailable]","tblsubjecttitles","[subjectavailable]=-'1'") with the same results.

    What happens is that the first time that there are no subjects selected, the form exits back to the main form; the second time the message box pops up.

    I've also used the code in a text box so that I can advise the users how many they have selected; the correct number shows, but it doesn't update in real time.

    Any help would be greatly appreciated.

  7. #7
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    I think I see one issue with your "full" version of DCount(). Your code states:
    Code:
    =DCount("[subjectavailable]","tblsubjecttitles","[subjectavailable]=-'1'")
    I think it needs to read:
    Code:
    =DCount("subjectavailable","tblsubjecttitles","[subjectavailable]=-1")
    OR
    Code:
    Dim blnTrue as Boolean
    blnTrue = True
    =DCount("subjectavailable","tblsubjecttitles","[subjectavailable]= " & blnTrue & "")
    I am not positive, but I think since you surrounded your 1 with '1' that it was treating it as text? I typically use variables in my DCounts/DLookups so I'm not positive on that.

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by jgelpi16 View Post
    Code:
    Dim blnTrue as Boolean
    blnTrue = True
    =DCount("subjectavailable","tblsubjecttitles","[subjectavailable]= " & blnTrue & "")
    try:


    Quote Originally Posted by jgelpi16 View Post
    Code:
    Dim blnTrue as Boolean
    blnTrue = True
    =DCount("subjectavailable","tblsubjecttitles","[subjectavailable]= " & blnTrue)
    I'm not even sure if booleans can be concated out like that.

  9. #9
    pwdpwd is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    UK - Barnsley
    Posts
    6
    Hi Guys - Thanks very much for the suggestions - I used the correct version of the DCount statement as the control of a text box (that I can use as a warning message, and also to check what was happening) and also in the VB. Both worked, but they were not updating in 'real time' - both the text field and the vb functionality were both '1 step behind' as it were.

    I then reasoned that I needed to do something with the checkbox; I did a bit of digging and used 'SaveRecord' as the after update event for the checkbox and the functionality of the exit button worked fine; not sure if its the right way of doing it, or if there's a better/simpler way, but it works.

    The number in the text box is still out of synch, but I can live without that.

    Thanks again for all your help - much appreciated.

  10. #10
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    ok, marked solved!

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

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2011, 10:39 AM
  2. Counting
    By rfs in forum Forms
    Replies: 0
    Last Post: 03-15-2011, 03:20 PM
  3. Counting Records
    By WhiteNite1971 in forum Access
    Replies: 1
    Last Post: 01-22-2011, 06:36 AM
  4. Counting across multiple fields
    By shak2 in forum Programming
    Replies: 37
    Last Post: 10-20-2010, 10:20 AM
  5. Simple query to show when items are not checked?
    By mrwistles in forum Queries
    Replies: 28
    Last Post: 09-02-2010, 02:52 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