open different forms based on the results of a count query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lwwhite
    New Member
    • Dec 2006
    • 16

    open different forms based on the results of a count query

    When a user clicks OK on form "SelectDefaults ," I want to open form "Welcome" if the results of query "qry_todo_overd ue" = 0 or form "OverdueToD o" if the results >= 1. First, I assume that I need to run the query in "SelectDefault' s" OnOpen event, right? But having done that, I'm not sure how to incorporate the query-checking into an If...Then statement on the OK button's OnClick event.

    Here is the query's SQL:

    SELECT Count(*) AS Expr1
    FROM tbl_tasklist
    WHERE (((tbl_tasklist .ptsk_duedate)< Date()) AND ((tbl_tasklist. ptsk_assigned)=[Forms]![SelectDefaults]![User]));

    On a related note, and you may prefer this to be a separate thread, I want to show or hide a button on a form ("iScope") based on the results of a query ("qry_todos_for _issue"). Here is that SQL:

    SELECT Count(*) AS Expr1
    FROM tbl_tasklist
    WHERE (((tbl_tasklist .ptsk_issue)=[Forms]![iScope]![issue]));

    Again, I assume the first step is to run "qry_todos_for_ issue" in "iScope's" OnOpen event. I guess I also need to run it in the OnCurrent event for when users open a different record while the form is still open? And then, I also don't know how to incorporate the query-checking into the button's code to determine the Visible property.

    If there is an altogether better way to accomplish either of these things other than with a query, I would love to know. Any help is much appreciated, as always!

    Leigh
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can retrieve the count in many ways. The easiest is to just use DLookup to get the value.
    Code:
    If DLookup("Expr1", "QueryName") = 0 Then
         ...
    Else
         ...
    End If

    Comment

    Working...