I have a listbox with a RowSource bound to an attached SQL Server table. If the table is large, Access does not load the complete result set but rather creates a server-side cursor and loads the data "on demand", as the list box is scrolled down. This is a nice feature, since it allows list boxes and combo boxes to show results fast.
However, this creates a shared lock on the table, i.e., no other user can insert new rows until the user with the list box has scrolled all the way down and the lock is released. This is a known problem.
To avoid this issue, I want to force Access to load all the rows into memory. By trial-and-error, I have found that accessing the ListCount
property seems to do exactly that:
myListBox.RowSource = "myTable"
' There are now shared locks on the table in SQL Server:
'
' ResourceType ObjectName IndexName RequestMode
' -------------------------------------------------------
' OBJECT myTable IS
' KEY myTable PK__myTable__17C... S
' PAGE myTable PK__myTable__17C... IS
someDummyVariable = myListBox.ListCount
' The locks are now gone!
How reliable is this method? If it isn't, is there a reliable method?
(I know about workarounds such as copying the data to a temporary table or creating a value list, but I'd rather avoid that, if possible.)