Solved

Listbox performance issue with value list - Access - VBA

Posted on 2014-03-25
13
1,295 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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 …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

756 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