Results 1 to 7 of 7
  1. #1
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287

    Count of records selected in a subform

    Hey guys,

    I have a form [Names] with an embedded subform [Names_sub]. The subform is lists of customers with a toggle on each record. The subform is linked to a query that is built directly on a table. The toggle is linked to "AddToList" field. The toggle changes the value to 1 or 2, 1 adds the name to the mailing list, 2 does not. I have a text box on [Names] with
    Code:
     =DCount("Name","T_DreamRooms","[AddToList] = '1' AND [Salesperson] = '" & [SlspSelect] & "'")
    On the AfterUpdate of the toggle, I have that DCount being requeried (sp?). All of the code is working, and the update is working. The problem is the dcount seems to be 1 less. If I select 3 names, the dcount will show 2. If I close that form (with those 3 names selected) and reopen it, it will say 3. Its like the [AddToList] value isn't changing until the next name is selected or the form closes. Is there a way to remedy this?



    I have to have a count of selected records, and it has to be updated as soon as a name is selected.

    I hope I gave enough info, let me know if you need more.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Need to commit the field edit to table. Edit is committed when:

    1. close form

    2. move to another record

    3. run code to save record

    Why use DCount()? Why not Count() in a textbox of the subform header/footer section. Textbox on main form can refer to the textbox of subform.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Ah ok, that makes sense.

    I used DCount() because I know how to. I've never even used Count() outside of the QBD grid. How would I use Count() for this?

    What code would I put in the AfterUpdate to save the record? Would that be the best way to do this?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    DoCmd.RunCommand acCmdSaveRecord

    Name textbox in subform header/footer tbxCount and expression in ControlSource: =Count(*)

    Expression in mainform textbox: =[subformcontainername].Form.tbxCount
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    The save command worked great.

    I'm confused with the Count() part. I only want to count the number of records where the toggle switch is set to "1." How do I do this with Count()?

    Appreciate the help.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    The toggle switch is bound to a field with value of 1 or 2?

    =Count(IIf([fieldname]=1,1))

    or

    =Sum(IIf([fieldname]=1,1))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Quote Originally Posted by June7 View Post
    The toggle switch is bound to a field with value of 1 or 2?
    Yes.


    I'll give that Count a try.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-01-2014, 04:09 PM
  2. Replies: 2
    Last Post: 04-30-2013, 07:55 PM
  3. Replies: 18
    Last Post: 01-27-2012, 12:53 PM
  4. Subform requery after multiple records selected
    By AccessBlues in forum Forms
    Replies: 8
    Last Post: 08-04-2011, 11:03 AM
  5. Show selected records in subform
    By Papilion in forum Forms
    Replies: 8
    Last Post: 06-18-2011, 07:41 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