Results 1 to 9 of 9
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    How to get a row count

    The follow segment of code works as intended. However, there are situations where the SELECT will return zero records. What can I add to the SELECT so I can detect zero recordcount?



    Code:
    Me.cboDescriptions.RowSource = "SELECT Description FROM tblRegister WHERE (((TDate)>#" & BegPeriod & "#) AND ((TTypeID)" & TTexp & ")) GROUP BY Description;"
                                   
    Me.cboDescriptions.Visible = True
    Me.cboDescriptions.SetFocus
    Me.cboDescriptions.Dropdown

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Perhaps you could use the DCount() function to return the number of records
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    Me.cboDescriptions.RowSource = "SELECT Description FROM tblRegister WHERE (((TDate)>#" & BegPeriod & "#) AND ((TTypeID)" & TTexp & ")) GROUP BY Description;"
    Is there a missing operator?? Maybe an "="???

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Never fails, if one doesn't post enough info it makes for un-answered questions. Here's the whole function:

    Code:
    Private Function FreqUsed(FUID As Integer)
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' From settings, get the number of months the user considers to be "Recent".  From
    ' that, get a list of descriptions used with the current transaction type and set
    ' that list as the RowSource of a combo box from which the user can chose or ignore.
    ' (6 months is the default if user hasn't defined otherwise.)
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim varTemp As Variant
    Dim BegPeriod As Date
    Dim intNumDays As Integer
    Dim TTexp As String
    
    
    varTemp = DLookup("[OrgRecent]", "tblSettings")
    If IsNull(varTemp) Or IsEmpty(varTemp) Or Not IsNumeric(varTemp) Then varTemp = 6
    
    BegPeriod = CDate(CLng(Date) - varTemp * 30)                  'Okay, BegPeriod now approximately varTemp months ago
    
        If FUID > 50 Then
            TTexp = "> 50"
        Else
            TTexp = "= " & FUID
        End If
        
    
    Me.cboDescriptions.RowSource = "SELECT Description FROM tblRegister WHERE (((TDate)>#" & BegPeriod & "#) AND ((TTypeID)" & TTexp & ")) GROUP BY Description;"
                                   
    Me.cboDescriptions.Visible = True
    Me.cboDescriptions.SetFocus
    Me.cboDescriptions.Dropdown
    
    End Function
    The first thing I tried was to save the SELECT as a string variable and then use DCount with the string as the domain but A2013 had fits with that approach. I can open a DAO recordset and get a RecordsetCount or save the SELECT as a QueryDef and use DCount, but I was thinking there could be a better way.

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    How about
    Code:
    debug.print cboDescriptions.listcount

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    I sensed there had to be an easier method. (Even old geezers learn something new every day )
    Thanks,
    Bill

    Code:
    If Me.cboDescriptions.ListCount > 0 Then      'Any history for the user to pick from?
        Me.cboDescriptions.Visible = True         'Yes. Make the combo visible and drop it down
        Me.cboDescriptions.SetFocus
        Me.cboDescriptions.Dropdown
    End If

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Are you ready to use the Thread Tools at the top of the Thread to mark this thread as Solved?
    https://www.accessforums.net/showthread.php?t=1828

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Sorry, totally focused on Christmas and birthdays this morning.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Completely understand. Merry Christmas!

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

Similar Threads

  1. Count the Count Query - Dsum NO-GO
    By Thomas1 in forum Queries
    Replies: 1
    Last Post: 10-24-2016, 12:27 PM
  2. Replies: 2
    Last Post: 06-30-2016, 06:38 PM
  3. Year Count and Month Count Same Query
    By NateSmith in forum Queries
    Replies: 1
    Last Post: 05-13-2015, 08:23 AM
  4. Replies: 2
    Last Post: 04-15-2014, 01:59 PM
  5. COUNT Group Count Records COUNT FUNCTION
    By PMCOFFEY in forum Access
    Replies: 9
    Last Post: 11-09-2012, 09:40 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