I have a form with multiple listboxes. The listboxes have a row source of a SELECT statement from a passthrough query which runs an EXEC statement against a SQL database.
Due to performance issues we have been monitoring the server with SQL Server Profiler and noticed that when you run .Requery on a listbox in the VBA code it actually runs the TSQL EXEC statement twice. I have stepped through the VBA code line by line and proved that it is the one line of code (listbox.requery) that creates the multiple calls.
Has anybody come across this and/or got any ideas of a solution.
For further clarification, The rowsource of the list box is set to 'SELECT * FROM qsptTestQuery'. I have an Access query object (named qsptTestQuery for example) which is a pass through query that returns rows. in the vba Code I set the .SQL of this object to 'Exec spTestProc 1234' and then run listbox.requery. when I run the listbox.requery line of code it triggers 2 calls in the profiler.
One solution is to call the pass-through query yourself in VBA, thereby giving you control over when it is called. The ListBox supports a custom-written function that can populate the list. Go here for details on how to specify and write the function.
This can give you finer control over population of the list, but as I recall it does not necessarily remove repetitive calls. In other words, you may find that it calls this functions multiples times with the initialization code. By tracing the calls, you can perhaps determine a pattern and write code which caches the values and only re-executes the pass-through query when necessary.
The following is an example from an old application and contains some of my comments that I hope are useful in writing your own. I've only ever had to do use this one time (out of many, many ListBox and ComboBox controls), but it worked well.