定制的ADO记录集和列表框...... [英] Custom-made ADO recordsets and listboxes...

查看:72
本文介绍了定制的ADO记录集和列表框......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个有趣的问题,有人可能会有答案...


前段时间,我写了一组实用程序类,它们包含了

将任意项添加到组合或

列表框所需的自定义行源函数。这一切都运行良好,并允许我通过点击列标题来做一些事情,例如

排序。


最近,这里的所有机器都升级到了Access XP从97和

我认为可能是时候利用新的ADO支持。

你可能知道,使用行源函数相当慢,甚至

具有优化的代码,并且滚动一个大的列表框并不是
完全是您可以拥有的最流畅的体验。如果你可以直接将列表框绑定到某些数据上,那就快了很多




所以我写了一些代码来创建一个断开连接的记录集,用我的数据填充它/ b $ b并将其附加到列表框中。问题是,我可以正确显示

列标题,我甚至可以将列表框显示为

显示正确的行数,但所有内容都是行

是空白的,无论我做什么。这里有一些简单的代码

说明:


创建一个新的空白表单。添加一个列表框和以下

程序:


Private Sub Form_Load()


Dim objRS As ADODB .Recordset


设置objRS =新ADODB.Recordset


使用objRS


调用.Fields .Append(" Item1",adChar,255)

致电。打开


致电.AddNew

.Fields(" ; Item1")。Value =" Test Line 1"

Call .AddNew

.Fields(" Item1")。Value =" Test Line 2"

调用.AddNew

.Fields(" Item1")。Value =" Test Line 3"

Call .Update


设置.ActiveConnection = CurrentProject.Connection

结束


设置List1.Recordset = objRS

结束Sub


如果您想知道,我必须设置ActiveConnection属性。

Access显然不支持绑定到断开连接的记录集。

我怀疑可能是pa rt的问题,但我不明白为什么。

当你在代码中查看记录集的内容时,似乎已经成功地完成了工作。


有人有什么想法吗?


提前致谢!


James

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
procedure:

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.
I suspect that might be part of the problem, but 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

推荐答案

James,


您可以从函数中填写一个列表框,该函数可以获取其数据
。这可能就是你要找的。


加里


" James Cane" < JW **** @ hotmail.com>在消息中写道

news:d5 ************************** @ posting.google.c om ...
James,

You can fill a list box from a function, and the function can get its data
from an array. That may be what you are looking for.

Gary

"James Cane" <jw****@hotmail.com> wrote in message
news:d5**************************@posting.google.c om...
这是一个有趣的问题,有人可能会有答案...

前段时间,我写了一组实用程序类,它们包含了
自定义行源函数需要将任意项添加到组合或
列表框中。这一切都运行良好,允许我点击列标题进行排序等事情。

最近,这里的所有机器都从97升级到Access XP和
我认为可能是时候利用新的ADO支持。
你可能知道,使用行源函数相当慢,甚至是优化的代码,并滚动一个大的列表框isn确切地说,你可以获得最流畅的体验。如果你能将列表框直接绑定到某些数据上,那就快得多了。

所以我写了一些代码来创建一个断开连接的记录集,用我的填充它
数据并将其附加到列表框。问题是,我可以正确显示
列标题,我甚至可以让列表框显示正确的行数,但行的所有内容都是空白的,不管我做什么。这里有一些简单的代码来说明:

创建一个新的空白表单。添加一个列表框和以下
程序:

Private Sub Form_Load()

Dim objRS As ADODB.Recordset

设置objRS =新ADODB.Recordset

使用objRS

调用.Fields.Append(" Item1",adChar,255)
调用。打开

Call .AddNew
.Fields(" Item1")。Value =" Test Line 1"
Call .AddNew
.Fields(" Item1")。Value =" ;测试线2
调用.AddNew
.Fields(" Item1")。Value =" Test Line 3"
Call .Update

设置。 ActiveConnection = CurrentProject.Connection
结束

设置List1.Recordset = objRS
结束子

如果您想知道,我必须设置ActiveConnection属性。
访问显然不支持绑定到断开连接的记录集。
我怀疑这可能是pr的一部分oblem,但我不明白为什么。
当你在代码中查看记录集的内容时,似乎已经成功地工作了。

任何人都有想法?

提前致谢!

James
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
procedure:

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.
I suspect that might be part of the problem, but 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



出于术语目的,您可能希望知道你在这里创造了什么

被称为伪造记录集,而不是断开连接的记录集。一个

断开连接的记录集必须一次连接。


现在,在Access 2000和2002中,您可以设置一个表单'.Recordset (不是
..RecordSource)属性到一个现有的记录集有一些限制,比如

因为Access希望任何ADO记录集都使用了特殊的ADP

围绕SQL Server连接的包装提供程序,例如什么

CurrentProject.ActiveConnection为您提供ADP。有时你可以用其他类型的ADO记录集来获取只读,但它已经命中或错过了,

并且有很多不应该做的事情如果你不想访问崩溃。


关于组合框和列表框,除非他们已经在Access 2003中添加了它们,这些

don没有.Recordset属性,所以你不能设置它。


现在,可以将行源类型(不是行源)设置为名称

a函数可用于填充列表框或组合框,我已经看到

这项工作非常好。可以编写该函数以从DAO或

ADO记录集返回数据,因此它为这些记录集提供了一种方法,可用作组合和列表框的源b / b
。在繁忙的网络上,这可能是一个功能强大的东西

,因为你可以在现代PC硬件上立即将一个过滤器应用于内存记录集的克隆。

。 br />

2004年1月12日11:49:09 -0800, jw****@hotmail.com (詹姆斯·凯恩)写道:
For terminology purposes, you might want to know that what you''ve created here
is called a fabricated recordset, not a disconnected recordset. A
disconnected recordset has to have at one time been connected.

Now, in Access 2000 and 2002, you can set a form''s .Recordset (not
..RecordSource) property to an existing recordset with some restrictions such
as the fact that Access expects any ADO recordset to have used the special ADP
wrapper provider around a SQL Server connection, such as what
CurrentProject.ActiveConnection gives you in an ADP. Sometimes you can get
away with other kinds of ADO recordsets for read-only, but it''s hit or miss,
and there are lots of don''ts if you don''t want Access to crash.

Regarding combo and list boxes, unless they''ve added it in Access 2003, these
don''t have the .Recordset property, so you can''t set it.

Now, it is possible to set the Row Source Type (not Row Source) to the name of
a function that can be used to populate a listbox or combo box, and I''ve seen
this work very well. The function can be written to return data from a DAO or
ADO recordset, so it provides a way for these recordsets to be used as sources
for combo and list boxes. On busy networks, this can be a powerful thing
since you can apply a filter to a clone of an in-memory recordset pretty much
instantly on modern PC hardware.

On 12 Jan 2004 11:49:09 -0800, jw****@hotmail.com (James Cane) wrote:
这是一个有趣的问题,有人可能有答案......

前一段时间,我编写了一组实用程序类,它们包含了将任意项添加到组合或
列表框所需的自定义行源函数。这一切都运行良好,允许我点击列标题进行排序等事情。

最近,这里的所有机器都从97升级到Access XP和
我认为可能是时候利用新的ADO支持。
你可能知道,使用行源函数相当慢,甚至是优化的代码,并滚动一个大的列表框isn确切地说,你可以获得最流畅的体验。如果你能将列表框直接绑定到某些数据上,那就快得多了。

所以我写了一些代码来创建一个断开连接的记录集,用我的填充它
数据并将其附加到列表框。问题是,我可以正确显示
列标题,我甚至可以让列表框显示正确的行数,但行的所有内容都是空白的,不管我做什么。这里有一些简单的代码来说明:

创建一个新的空白表单。添加一个列表框和以下
程序:

Private Sub Form_Load()

Dim objRS As ADODB.Recordset

设置objRS =新ADODB.Recordset

使用objRS

调用.Fields.Append(" Item1",adChar,255)
调用。打开

Call .AddNew
.Fields(" Item1")。Value =" Test Line 1"
Call .AddNew
.Fields(" Item1")。Value =" ;测试线2
调用.AddNew
.Fields(" Item1")。Value =" Test Line 3"
Call .Update

设置。 ActiveConnection = CurrentProject.Connection
结束

设置List1.Recordset = objRS
结束子

如果您想知道,我必须设置ActiveConnection属性。
访问显然不支持绑定到断开连接的记录集。
我怀疑这可能是问题的一部分,但我可以'看看为什么。
当你在代码中查看记录集的内容时,似乎已经成功地工作了。

有人有任何想法吗?

提前致谢!

James
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
procedure:

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.
I suspect that might be part of the problem, but 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






这对access97不起作用...

两行失败

设置.ActiveConnection = CurrentProject.Connection(未定义变量)

设置List1.Recordset = objRS(未找到数据成员) )

jw****@hotmail.com (詹姆斯·凯恩)在留言中写道:< ; D5 ******** @ posting.google。 com> ...
this doesn''t work with access97...
the two lines fail
Set .ActiveConnection = CurrentProject.Connection (undefined variable)
Set List1.Recordset = objRS (data member not found)

jw****@hotmail.com (James Cane) wrote in message news:<d5**************************@posting.google. com>...
这是一个有趣的问题,有人可能会有答案......

前段时间,我写了一组实用工具类,结束将任意项添加到组合或
列表框所需的自定义行源函数。这一切都运行良好,允许我点击列标题进行排序等事情。

最近,这里的所有机器都从97升级到Access XP和
我认为可能是时候利用新的ADO支持。
你可能知道,使用行源函数相当慢,甚至是优化的代码,并滚动一个大的列表框isn确切地说,你可以获得最流畅的体验。如果你能将列表框直接绑定到某些数据上,那就快得多了。

所以我写了一些代码来创建一个断开连接的记录集,用我的填充它
数据并将其附加到列表框。问题是,我可以正确显示
列标题,我甚至可以让列表框显示正确的行数,但行的所有内容都是空白的,不管我做什么。这里有一些简单的代码来说明:

创建一个新的空白表单。添加一个列表框和以下
程序:

Private Sub Form_Load()

Dim objRS As ADODB.Recordset

设置objRS =新ADODB.Recordset

使用objRS

调用.Fields.Append(" Item1",adChar,255)
调用。打开

Call .AddNew
.Fields(" Item1")。Value =" Test Line 1"
Call .AddNew
.Fields(" Item1")。Value =" ;测试线2
调用.AddNew
.Fields(" Item1")。Value =" Test Line 3"
Call .Update

设置。 ActiveConnection = CurrentProject.Connection
结束

设置List1.Recordset = objRS
结束子

如果您想知道,我必须设置ActiveConnection属性。
访问显然不支持绑定到断开连接的记录集。
我怀疑这可能是pr的一部分oblem,但我不明白为什么。
当你在代码中查看记录集的内容时,似乎已经成功地工作了。

任何人都有想法?

提前致谢!

詹姆斯
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
procedure:

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.
I suspect that might be part of the problem, but 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



这篇关于定制的ADO记录集和列表框......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆