Results 1 to 15 of 15
  1. #1
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121

    Unhappy What is quicker way to retrieve data

    I have PO detail in backend table in SQL server. This is PO detail table which is very large table millions of records. I have almost 100 POs to get all PO details.



    If I create table listed 100 POs and link to backend table it takes lots of time to retrieve it. If I put PO nbr in POs feild in query IN ("POnbr1","POnbr2", "POnbr3"....................) means I have to copy and paste all POs in IN (.....). it gives me result very quick.

    Is there any possibility I dont need to copy paste. If I make list in forms and select all to run query.

    Is there any good solution to get data quicker ? or setup recordset in vba ?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    you dont need the IN (...) to pull the data.
    create a query, to pull your data using the WHERE criteria

    select * from table where [poID] like "POnbr*"

  3. #3
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121
    Quote Originally Posted by ranman256 View Post
    you dont need the IN (...) to pull the data.
    create a query, to pull your data using the WHERE criteria

    select * from table where [poID] like "POnbr*"
    I have query but if I have 100 POs to pull then

    Select * from table where PoId IN (POnbr1, POnbr2.......................) which is really pain in the butt.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Using IN or a list in WHERE is the same, both give the list of available values. I prefer IN myself, easier to see. I don't know if there is a limit in SQL Server on the length of this, however, how many values you are allowed.

    You need to make a VBA subroutine which reads the table with the list of PO numbers and creates the IN(...) string, which you will then use in creating the pass-thru query.

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    The IN is bad way to do it.
    use another lookup table of POs and join it to the main table.
    this will pull only those in the list.

  6. #6
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    Quote Originally Posted by adnancanada View Post
    If I create table listed 100 POs and link to backend table it takes lots of time to retrieve it.
    Do you have an index on the PO number field in SQL? This could speed up the search. Also make sure it is a pass-through query so it runs quicker and does processing on SQL server.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    See this article.


    You can use it to exclude or adjust to include.

    Good luck.

  8. #8
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121
    Quote Originally Posted by aytee111 View Post
    Using IN or a list in WHERE is the same, both give the list of available values. I prefer IN myself, easier to see. I don't know if there is a limit in SQL Server on the length of this, however, how many values you are allowed.

    You need to make a VBA subroutine which reads the table with the list of PO numbers and creates the IN(...) string, which you will then use in creating the pass-thru query.
    Can we run any simple query via vba.

    Select * from POdetail where POnbr IN ('4500909343', '4560990090', '4530009099'.....)

  9. #9
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    What are you doing with the detail data once retrieved from SQL? Displaying on a form or report? Are these 100 PO numbers going to change daily or is it same 100 each day?

    Check that there is an index on the PONumber in your SQL table, will speed up the query no matter which way you do it.

  10. #10
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121
    Quote Originally Posted by Bulzie View Post
    What are you doing with the detail data once retrieved from SQL? Displaying on a form or report? Are these 100 PO numbers going to change daily or is it same 100 each day?

    Check that there is an index on the PONumber in your SQL table, will speed up the query no matter which way you do it.
    No everyday I have to change it. I want to make it more automated. Just upload POs and run query.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  12. #12
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    What's the nature of the 100 POs you have to input each day. Is it possible to use criteria to get them from a recordset each day instead of you having to type them in?

  13. #13
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121
    Quote Originally Posted by Bulzie View Post
    What's the nature of the 100 POs you have to input each day. Is it possible to use criteria to get them from a recordset each day instead of you having to type them in?
    Third party logistic give us around 100 POs which exists in SQL server. Based on these PO, we need to get weight, volume and PO date created from PO detail. I created a table with one field "POnbr" on SQL Server via pass through query. When I link this table with POdetail table it stuck. It takes lot of time and ended up with odbc connection failier. When I use IN operator in query it works fine.

    I want to know how vba code to run it. I simply want to run below query.

    Select PO, weight, volume, pocreated from POdetail where PO IN (my 100 POs)

  14. #14
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    Since you have to input the 100 POs each day manually, you won't get any benefit from vba code creating the IN() PO values as you will be typng them in anyway. So put that select statement into a passthrough query in Access, set up the ODBC connection in properties and run it. If you get syntax errors, go to SQL and run your query there to make sure it works and is pulling correctly, then copy that SQL code to put in your Passthrough query in Access.

  15. #15
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121
    Quote Originally Posted by Bulzie View Post
    Since you have to input the 100 POs each day manually, you won't get any benefit from vba code creating the IN() PO values as you will be typng them in anyway. So put that select statement into a passthrough query in Access, set up the ODBC connection in properties and run it. If you get syntax errors, go to SQL and run your query there to make sure it works and is pulling correctly, then copy that SQL code to put in your Passthrough query in Access.
    Dear my pass through query is working fine some time I have more than 400POs what should I do in this case ? I cant type 400 POs or copy paste 400 there is limit of IN operator.

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

Similar Threads

  1. Retrieve a data by using query
    By trident in forum Queries
    Replies: 7
    Last Post: 02-03-2016, 11:33 PM
  2. using SQL in VBA to retrieve data
    By sovereign in forum Access
    Replies: 8
    Last Post: 08-25-2015, 10:17 AM
  3. Replies: 3
    Last Post: 03-06-2014, 10:26 AM
  4. Programming Access - is there a quicker\better way?
    By shabbaranks in forum Programming
    Replies: 2
    Last Post: 08-25-2012, 10:42 AM
  5. Retrieve Data Too Slow
    By BGF in forum Programming
    Replies: 8
    Last Post: 09-08-2010, 04:28 PM

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