none
Needs to show zero if no record count in a subform RRS feed

  • Question

  • Good morning,

    Ah those zeros stuff, I just want to show 0 if there is no records in a subform and instead, I received the famous word #Erreur...

    When I have purchase, the CountPurchase field is updating perfectly, but when no purchase is done, I expect to see nothing or a zero (0), can't achieve that

    I then create a field named "Purchase" to see if the recordsetclone could work, the only thing that is showing is "NoPurchase" and I have this code:

    Private Sub Form_AfterUpdate()
    Dim recClone As Object
    Set recClone = Forms![frmCarteRepasLues].[frmTotalAchatsDétenteurs].Form.RecordsetClone
    
    If recClone.RecordCount = 0 Then
    Me.Purchase = "NoPurchase"
    End If
    If recClone.RecordCount > 0 Then
    Me.Purchase = "Has purchases"
    End If
    End Sub

    So I try this one:

    Private Sub Form_AfterUpdate()
    Dim recClone As Object
    Set recClone = Forms![frmCarteRepasLues].[frmTotalAchatsDétenteurs].Form.RecordsetClone
    
    If recClone.RecordCount = 0 Then
    Me.Purchase = "NoPurchase"
    else
    Me.Purchase = "Has purchases"
    End If
    End Sub

    No luck either, the default value is 0 but it should change for "Has purchase"...

    Anyway, here is 3 images to show the form I have problems with can you help?:

    With 1 purchase:

    With 2 purchases

    When customer has no purchase:


    Claude Larocque

    Saturday, August 20, 2016 6:15 AM

Answers

  • I would suggest DCount.

    Example:

    PrivateSubForm_AfterUpdate()

        Me.Purchase = IIf(DCount("*","SubTableName") = 0,"NoPurchase", "Has purchases")

    EndSub

    Saturday, August 20, 2016 6:53 AM

All replies

  • I would suggest DCount.

    Example:

    PrivateSubForm_AfterUpdate()

        Me.Purchase = IIf(DCount("*","SubTableName") = 0,"NoPurchase", "Has purchases")

    EndSub

    Saturday, August 20, 2016 6:53 AM
  • Thanks basharp but it didn't work, however you put me on the right track, so I use DCount somewhere else and it works...

    Have a great week-end

    Claude


    Claude Larocque

    Saturday, August 20, 2016 12:31 PM