Solved

Listbox performance issue with value list - Access - VBA

Posted on 2014-03-25
13
1,280 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
  • 7
  • 4
  • 2
13 Comments
 
LVL 36

Assisted Solution

by:PatHartman
PatHartman earned 50 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 47

Expert Comment

by:Dale Fye (Access MVP)
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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 450 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 47

Expert Comment

by:Dale Fye (Access MVP)
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 36

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 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 450 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

829 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