Solved

Listbox performance issue with value list - Access - VBA

Posted on 2014-03-25
13
1,242 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 34

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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 34

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now