J
James Cane
Here's an interesting problem that someone might have an answer to...
Some time ago, I wrote a set of utility classes which wrap up the
custom row source function needed to add arbitrary items to a combo or
listbox. It all works nicely and allows me to do things such as
sorting by clicking on column headings.
Recently, all the machines here were upgraded to Access XP from 97 and
I thought it might be time to take advantage of the new ADO support.
As you might know, using a row source function is rather slow, even
with well optimised code, and scrolling through a large list box isn't
exactly the smoothest experience you can have. It's all a lot faster
if you can bind the listbox directly to some data.
So I wrote some code to create a disconnected recordset, populate it
with my data and attach it to a listbox. The thing is, I can get the
column headings to show correctly and I can even get the listbox to
display the correct number of rows, but all the contents of the rows
are blank, no matter what I do. Here's some simple code to
illustrate:
Create a new blank form. Add one list box and the following
code:
Private Sub Form_Load()
Dim objRS As ADODB.Recordset
Set objRS = New ADODB.Recordset
With objRS
Call .Fields.Append("Item1", adChar, 255)
Call .Open
Call .AddNew
.Fields("Item1").Value = "Test Line 1"
Call .AddNew
.Fields("Item1").Value = "Test Line 2"
Call .AddNew
.Fields("Item1").Value = "Test Line 3"
Call .Update
Set .ActiveConnection = CurrentProject.Connection
End With
Set List1.Recordset = objRS
End Sub
In case you're wondering, I have to set the ActiveConnection property.
Access apparently doesn't support binding to disconnected recordsets,
which I suspect that might be part of the problem, although I can't
see why.
When you look at the contents of the recordset in code, it all seems
to have worked successfully.
Anybody got any ideas?
Thanks in advance!
James
Some time ago, I wrote a set of utility classes which wrap up the
custom row source function needed to add arbitrary items to a combo or
listbox. It all works nicely and allows me to do things such as
sorting by clicking on column headings.
Recently, all the machines here were upgraded to Access XP from 97 and
I thought it might be time to take advantage of the new ADO support.
As you might know, using a row source function is rather slow, even
with well optimised code, and scrolling through a large list box isn't
exactly the smoothest experience you can have. It's all a lot faster
if you can bind the listbox directly to some data.
So I wrote some code to create a disconnected recordset, populate it
with my data and attach it to a listbox. The thing is, I can get the
column headings to show correctly and I can even get the listbox to
display the correct number of rows, but all the contents of the rows
are blank, no matter what I do. Here's some simple code to
illustrate:
Create a new blank form. Add one list box and the following
code:
Private Sub Form_Load()
Dim objRS As ADODB.Recordset
Set objRS = New ADODB.Recordset
With objRS
Call .Fields.Append("Item1", adChar, 255)
Call .Open
Call .AddNew
.Fields("Item1").Value = "Test Line 1"
Call .AddNew
.Fields("Item1").Value = "Test Line 2"
Call .AddNew
.Fields("Item1").Value = "Test Line 3"
Call .Update
Set .ActiveConnection = CurrentProject.Connection
End With
Set List1.Recordset = objRS
End Sub
In case you're wondering, I have to set the ActiveConnection property.
Access apparently doesn't support binding to disconnected recordsets,
which I suspect that might be part of the problem, although I can't
see why.
When you look at the contents of the recordset in code, it all seems
to have worked successfully.
Anybody got any ideas?
Thanks in advance!
James