Results 1 to 2 of 2
  1. #1
    quicova is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    53

    Set Default criteria to query

    Hello everyone



    I have a form with comboboxes as criteria to a query.
    If the form is closed and I want to open the query it asks me for the values in the form.

    Is there a way to set default values to open the query without having to open the form?

    the reason for this is I want to put the form on a navigation Form, the form is a continuous Form with the data from the query.
    I already set the default values for the form to "" but When I had the form to the navigation it keeps asking me for the criteria values for the query.
    Every time I change tabs in the navigation form, it asks for the criteria values.

    I'm guessing the problem is in the query, because it need the criteria values.
    Thanks so much
    Francisco

  2. #2
    Join Date
    Jul 2011
    Posts
    17
    Hi Francisco,

    I think there's a good chance I don't understand the problem, but how about this...

    Code:
    Function GetValue(ControlName As String, DefaultValue As Variant)
    If IsOpen(Forms("MyFormName").Name) Then
        GetValue = Forms("MyFormName").Controls(ControlName)
    Else
        GetValue = DefaultValue
    End If
    End Function
    
    
    Function IsOpen(FormName As String, Optional intObjectType As Integer = acForm)
    'Access 97
    IsOpen = (SysCmd(acSysCmdGetObjectState, intObjectType, FormName) <> 0)
    
    
    'Access 2000 and up
    IsOpen = currentproject.allforms(FormName).IsLoaded
    End Function
    Then put

    =GetValue("cboCompanyName","Microsoft")

    or whatever into your query

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

Similar Threads

  1. Replies: 4
    Last Post: 05-02-2013, 11:07 AM
  2. Replies: 5
    Last Post: 09-20-2012, 03:27 PM
  3. Replies: 5
    Last Post: 08-02-2012, 09:44 AM
  4. Replies: 1
    Last Post: 07-13-2011, 11:00 AM
  5. In query: check criteria with default value
    By hoachen in forum Access
    Replies: 1
    Last Post: 07-12-2011, 10:23 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