Results 1 to 6 of 6
  1. #1
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143

    Query Criteria that Checks if a Form is Open


    I have a query that currently prompts the user to enter a confirmation number [ConfID] whenever it is run. I would like to change the criteria, so that IF the Form that is used to enter records is open, it pulls the ConfID from the current record on the form, and otherwise continues to prompt the user to enter the ConfID.

    I have tried variations of =IIf(CurrentProject.AllForms("F-OrderConf").IsLoaded=TRUE, [Forms]![F-OrderConf]![ConfID], [Enter ConfID])
    but am told that "IsLoaded" is an invalid syntax.

    I don't know how to code, so am hoping this can be solved using the expression builder.

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    Why not just but button on the Form so that it will run the query based on the current record each time instead of them having to put in a number. Are both the Form and Query based on the same Table?

  3. #3
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    In the criteria line in your query, type GetValue().

    Then add this function in a new module in VBA (change the names to match your database):
    Code:
    Public Function GetValue()
    
        If CurrentProject.AllForms("Form1").IsLoaded = True Then
            GetValue = Forms!Form1!f1
        Else
            GetValue = InputBox("Enter Value")
        End If
    
    End Function

  4. #4
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    Yes the Query and Form are based on the same tables (more than one). The Query is effectively only run when a connected report is opened for printing.

    The button that is currently on the Confirmation Form doesn't actually run the query, but opens a new PrintOptions form that prompts the user to select what report they would like to print (There are a series of queries and reports all based on the same tables). The user can also print (open the PrintOptions form) directly from the Main Menu without opening the Confirmation Form at all (which is the circumstance that I would still want the user to enter ConfID).

    Would it be possible to create an identical PrintOptions form with print buttons that run the query based on the open Confirmation Form? And how would I get the buttons to do that when the Query still has the [Enter ConfID] Criteria?

  5. #5
    PeakH is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    143
    I didn't see the response from aytee111 before responding myself, but your suggestion worked!

    Thank you!
    And that was my first go at VBA and modules. (Not as scary as I thought)

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    A whole new world - go get 'em!

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

Similar Threads

  1. Replies: 4
    Last Post: 08-09-2016, 06:07 AM
  2. Creating a form that checks for Data entry
    By TLCTech in forum Forms
    Replies: 1
    Last Post: 12-23-2015, 01:40 PM
  3. Clear Filters and Checks on Load--Form
    By nick404 in forum Forms
    Replies: 11
    Last Post: 06-09-2015, 10:46 AM
  4. Replies: 2
    Last Post: 06-22-2014, 09:49 PM
  5. Open 2nd Form with 2 criteria?
    By Robeen in forum Forms
    Replies: 1
    Last Post: 09-19-2011, 10:20 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