Results 1 to 5 of 5
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    why is query so much faster using value from form as criteria vs using where condition to open form

    First of all my table is in sql server so I know that may affect the answers.



    I have a form where I let the user enter a railcar id and then show a list of invoices for that railcar. If I create the query to have a criteria of a value on the form, something like this, [Forms]![NavigationForm]![NavigationSubform].[Form]![RailcarID] it will load in 1-2 seconds.

    However, If I create a variable form the value on the form and pass it to the form as a where condition it takes 25 seconds. Something like this

    Dim FAvar As String
    FAvar = Me.RailCarID
    DoCmd.OpenForm "f_AllVendorInvoices-Where", acNormal, , "[RailcarID] = " & Me.RailCarID & ""

    Why is there such a big difference in speed and is there a way to speed it up and still just use the where condition?

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Is the server local? How many records are in the invoice table?

    Purely a guess but maybe the second method is first getting all the invoice records and then access is filtering them down by the railcareid where as the first method is using standard sql and letting the server on the back end handle the processing.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,008
    That is what it does, doesn't it, it just sets a filter when opening the form?
    Remove the filter and you should get all the records?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Yes, the server is local and there are about 600K records on the table. It must be that with the filter criteria in the query access looks at the SQL table and only searches for records with that RailcarID but using the where clause it must try to pull the entire table into access and then look for the railcarid. So like welshgasman says the where condition is loading the entire table, then filtering for the selection. Using the select query i guess it filters on sql server (much faster) then only loads to access the selected records.

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    The where parameter of docmd.openform is poorly named - it is a filter, not a criteria. As WGM says you can remove the filter once opened to show all the records. Instead move your where parameter value to the openargs parameter and in the form open event put something like

    Me.recordsource = Me.recordsource & “ where “ & me.openargs

    now back on my computer (difficult to write code on a phone) so better to have the form recordsource as

    SELECT * FROM myTable WHERE False

    so no records are returned

    then in the form load event

    Me.recordsource = replace(Me.recordsource,"false", me.openargs)
    Last edited by CJ_London; 03-18-2022 at 07:12 PM.

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

Similar Threads

  1. Replies: 47
    Last Post: 07-12-2017, 08:51 AM
  2. Where Condition in Open Form Command
    By Srin in forum Access
    Replies: 11
    Last Post: 10-12-2015, 07:26 AM
  3. Open another Form if condition is true
    By sjacksontx in forum Forms
    Replies: 3
    Last Post: 03-27-2015, 01:24 PM
  4. docmd.open form between dates condition
    By Ruegen in forum Programming
    Replies: 6
    Last Post: 09-22-2013, 11:23 PM
  5. Button to open form with a Where condition
    By Newbie2 in forum Forms
    Replies: 3
    Last Post: 08-07-2012, 01:19 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