Results 1 to 3 of 3
  1. #1
    dso808 is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    6

    How to determine if records returned upon open of report

    In VBA, how to I find out, upon open of a report, if any records were returned?



    I have a report which has a query setup in the Report > Record Source property. It works fine, but there's a situation where I'll need to know if NO records are returned from that query when the report is opened.

    Here's the script:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Val(Format(Nz(Me.EstDueDate, "1/1/3000"), "yyyymmdd")) <= Val(Format(Me.txtDate, "yyyymmdd")) Then
    'MsgBox (Me.txtSR)
    Me.lblPastDue.Visible = True
    Else
    Me.lblPastDue.Visible = False
    End If
    End Sub

    So before the first IF, I'll need to put another IF statement to find out if any records are returned. If none are returned, this script breaks unless I put in that IF.

    Thanks in advance to all who reply!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Try:
    If Me.HasData Then
    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
    dso808 is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    6
    Thanks June7! Works like a charm:

    If Me.HadData Then
    'Do Stuff
    EndIf

    Have a great weekend and thanks again

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

Similar Threads

  1. Replies: 1
    Last Post: 04-12-2011, 05:19 PM
  2. Replies: 2
    Last Post: 08-17-2010, 10:54 AM
  3. How do I determine a SQL query result?
    By Trainman in forum Database Design
    Replies: 1
    Last Post: 10-15-2009, 04:49 AM
  4. Replies: 6
    Last Post: 09-25-2009, 12:40 PM
  5. Counting returned records in a query
    By johncob in forum Queries
    Replies: 0
    Last Post: 02-11-2009, 05:30 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