Results 1 to 2 of 2
  1. #1
    fahnoubi is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Mar 2013
    Posts
    1

    Query criteria from public variable or from form, when form is closed


    Hello,


    After a few hours searching, I couldn't find any solution to this little problem I'm having.


    I have a query that retrieves one of its criteria from a form. I have referenced correctly the value on the form from the query, and it works, but what I wanted to do is a bit more complicated: when the form is closed, I want to launch the query with a "default value".


    I tried to do it in 2 different ways:
    a) Defining an "IIf" at the query criteria: I would need a function that checks if the form from which I retrieve the values is open.
    b) Defining public variables with a default value, which would be changed from the form: I don't know where/when to initialize the value of the variable.




    Does anyone have a better idea on how to do this?


    TL;DR: Query gets criteria from form when it's open. If form is closed, query uses default value. HELP!

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    What are you doing with the query. Is it the basis for a report? or are you viewing the query within your access application.


    If the query is the data source for some other item you can alter recordsources. If you are actually viewing the contents of the query directly in your application or, say, trying to export the resulting query there's no simple way to do what you want other than having two distinct queries, then when you click your button to run your query when your form is not open if opens QueryA instead of QueryB.

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

Similar Threads

  1. Form not getting closed at first time
    By vikasbhandari2 in forum Programming
    Replies: 10
    Last Post: 07-20-2012, 01:25 PM
  2. Replies: 1
    Last Post: 03-30-2012, 11:57 PM
  3. Replies: 4
    Last Post: 08-17-2011, 05:30 AM
  4. Using Form Variable in Query Criteria
    By Greg.Terry in forum Queries
    Replies: 3
    Last Post: 04-01-2011, 08:06 PM
  5. VBA public procedure in a form
    By gg80 in forum Programming
    Replies: 3
    Last Post: 09-12-2010, 04:55 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 - Senior Forums