Results 1 to 5 of 5
  1. #1
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    testing query for results

    Hi



    I'm opening a form using the following code

    Private Sub btnAllbannsFiltered_Click()
    DoCmd.Close
    DoCmd.OpenForm FormName:="frm_BannsFiltered"
    End Sub
    [/CODE]

    The form frm_BannsFiltered is based on a query which itself based on tempvars selected by the user so sometimes the query will have no results

    The query is named qry_AllBannsFiltered

    What I would like to do is to run the query to see if there are any records is not I would like it to open a message box saying "There are not results for this Search"
    If there are results then open the form.

    MY logic such as it is to to do this before the DoCmd Close using Else but my attempts seem to fail

    Is my logic wrong?

    thanks

    Ian

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Code:
    If DCount("*", "QueryName") > 0 Then
      Your Code Here
    Else
      Message box to user
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Your code:
    Code:
    Private Sub btnAllbannsFiltered_Click()
    Dim nCount as long
    nCount = Dcount("*", "qry_AllBannsFiltered"
    if nCount > 0 then 
        DoCmd.Close 
        DoCmd.OpenForm FormName:="frm_BannsFiltered"
    else 
        MsgBox "No records to process"
    endif
    End Sub

  4. #4
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi

    Many thanks must get into Dcount!

    cheers

    Ian

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Testing
    By alansidman in forum General Chat
    Replies: 5
    Last Post: 10-24-2013, 03:58 PM
  2. Replies: 5
    Last Post: 05-21-2013, 02:21 PM
  3. Replies: 3
    Last Post: 05-02-2013, 10:36 AM
  4. Replies: 6
    Last Post: 05-14-2012, 07:24 AM
  5. Replies: 3
    Last Post: 11-08-2010, 11:09 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