Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Listbox performance issue with value list - Access - VBA

Posted on 2014-03-25
13
Medium Priority
?
1,380 Views
Last Modified: 2014-03-26
Hi experts, I have an issue with a list box performance when loading  the data, It is loading fast when the form open first time based on a combo box value, But after some  form operations (successful insert/update data to table using the form) - this list box  taking too much time to load (more than 3 minutes). When i checked the code with break point - seems like it is hanging on the while loop to add stritem  to the list box.
Can somebody please help me.
Thanks


Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim strSQL1 As String
   Dim strItem As String
   Set db = CurrentDb
     strSQL1 = "SELECT  * FROM Employee WHERE ((Person_Number)  not in (select person_number from Employee_Room_Status WHERE Employee_Room_Status.Employee_Active = true and Employee_Room_Status.Room_ID =" & Me.Combo_Room.Value & "))"
     Set rs = db.OpenRecordset(strSQL1)
   Do Until rs.EOF
      strItem = rs.Fields("Last_Name").Value & ";" _
         & rs.Fields("First_Name").Value & ";" _
         & rs.Fields("Middle_Initial").Value & ";" _
         & rs.Fields("Person_Number").Value
      Me.List1Edit.AddItem strItem      ' Row Source Type must be Value List
      rs.MoveNext

   Loop
   rs.Close
   Set rs = Nothing
   Set db = Nothing
0
Comment
Question by:gtmathewDallas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
13 Comments
 
LVL 39

Assisted Solution

by:PatHartman
PatHartman earned 150 total points
ID: 39954603
Try creating a second query with the necessary selection criteria and join to it using a Left Join rather than using a subquery.  Joins are sometimes more efficient than subqueries.
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39954662
Your problem is the Not IN clause in your SQL statement.  IN clauses are notoriously slow.  Try:

strSQL1 = "SELECT  * FROM Employee "
               & "LEFT JOIN (" _
               & "SELECT person_number from Employee_Room_Status " _
               & "WHERE Employee_Room_Status.Employee_Active = -1 " _
               & " AND Employee_Room_Status.Room_ID = " & Me.Combo_Room.Value _
               & ") as Temp " _
               & "ON Employee.Person_Number = Temp.Person_Number " _
               & "WHERE Temp.Person_Number IS NULL"

Is there a reason for the value list rather than using this as the RowSource for a listbox with a RowSourceType of 'Table/Query'?
0
 

Author Comment

by:gtmathewDallas
ID: 39954776
It still showing the delay, the noticed thing is - this problem only happening after the table update.
Is that because of not refreshing the table? Its not showing any issues to load the contents, when we close and re open the database.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 48

Assisted Solution

by:Dale Fye
Dale Fye earned 1350 total points
ID: 39954856
As I asked before, is there a reason that the RowSourceType must be a ValueList, and not Table/Query.  That query should run relatively quickly if you rewrote it like:

SELECT  [Last_Name], [First_Name]. [Middle_Initial[, [Person_Number]
FROM Employee
LEFT JOIN (
SELECT person_number
FROM Employee_Room_Status
WHERE Employee_Room_Status.Employee_Active = -1
AND Employee_Room_Status.Room_ID = [Forms]![YourFormName].Combo_Room
) as Temp
ON Employee.Person_Number = Temp.Person_Number
WHERE Temp.Person_Number IS NULL

If you save that query, you can set the RowSourceType to Table/Query and set the RowSource to that query, and simply requery the listbox whenever something changes.
0
 

Author Comment

by:gtmathewDallas
ID: 39956122
I am sorry, I missed to answer that question, Yes, I have to compare two list boxes (to add/remove from one to another), so using the value list.

I will check with the above query now
Thanks a lot
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39956128
I do something similar with queries, and avoid all of the additional overhead of having to clear the list and add items to the list.
0
 
LVL 39

Expert Comment

by:PatHartman
ID: 39956137
I also use queries.  As data is "moved" from one listbox to the other, data is updated and the queries rerun.
0
 

Author Comment

by:gtmathewDallas
ID: 39956216
Getting - Error 6014 - row source must be value list to use this method - when I am trying to move items from this list(List1Edit) to other one(List2Edit) - or moving from other one to this list box.
0
 

Author Comment

by:gtmathewDallas
ID: 39956226
I used the below  method to move items to and fro
http://support.microsoft.com/kb/278378
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 1350 total points
ID: 39956257
I use a similar technique, but I use the tables and insert and delete SQL operations to add items from one list to another.

I don't have a sample readily available, but If I can find one or whip one up, I'll try.
0
 

Author Comment

by:gtmathewDallas
ID: 39956287
Thank you so much, I really appreciate your help...
0
 

Author Comment

by:gtmathewDallas
ID: 39957318
I am using now the query as row source of this list box now, but to update the table need the values from the list,
Is there any way to get all column values (i have 4 columns in my list)  of a selected row in a list box? I think that will help me to finish this task.
0
 

Author Comment

by:gtmathewDallas
ID: 39957438
Yes I got it, Thanks so much fyed  and PatHartman
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question