A97中的回调函数重新查询问题 [英] Callback Function requery problem in A97

查看:99
本文介绍了A97中的回调函数重新查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


也许我只是在这里错过了一些简单的东西,但我似乎在A97中有一个带回调函数的

问题用于填充列表框

的值。第一次使用回调函数(当

表单打开时)一切运行良好,每个人都很高兴。然后是

问题 - 值被添加到记录集(ADO),回调

函数用来填充列表框。


将新值添加到记录集后,

的显而易见的事情是对列表框使用requery方法,从而激活

回调函数,以及从理论上说,重新填充列表框的值为

。这不是正在发生的事情。事实上,在回调中发生的事件

序列甚至没有击中事件6

(acLBGetValue)或事件3(acLBGetRowCount),它就像这样...... 8-> 2-


> 8-> 9-> 0-> 2-> 1并在那里结束。不知何故,不知怎的,神奇地,即使没有



代码与任何这些情况下的数据填充相关,记录

出现在列表框中代码崩溃说

记录集是EOF或BOF ....


现在我让F8通过这个步骤,这里是另一个最好的b $ b好​​奇的事情:关闭代码窗口后,我再次得到EOF或BOF

消息并跳转到调试并猜测是什么?它在事件6尝试

来获取数据!我在这里疯了还是我错过了什么?b $ b完全,或者是我的A97我必须在这里决定用我的脑子来玩

?下面是回调函数代码的副本。

ADO记录集有两个字段,都是文本。哦是的,我正在尝试

将字段名称作为列标题放置(似乎工作正常)。


函数映射(ctl As Control, _

varId As Variant,lngRow As Long,lngCol As Long,_

intCode As Integer)As Variant


Dim varRetval作为Variant


选择案例intCode

案例acLBInitialize

''你能初始化吗?

如果rsCategoryMap.RecordCount 0然后

rsCategoryMap.MoveFirst

结束如果

varRetval = True


案例acLBOpen

''什么是唯一标识符?

varRetval =计时器


案例acLBGetRowCount

''有多少行?

如果rsCategoryMap.RecordCount = 0那么

varRetval = 1

Else
varRetval = rsCategoryMap.RecordCount + 1

rsCategoryMap.MoveFirst

结束如果


Case acLBGetColumnCount
''有多少列?

varRetval = rsCategoryMap.Fields.Count


Case acLBGetValue

''什么'' s每行/每列的值是多少?

选择案例lngRow

案例(0)

varRetval = rsCategoryMap.Fields(lngCol) .Name

Case Else

选择案例lngCol

案例(0)

varRetval = rsCategoryMap.Fields(lngCol ).Value

Case Else

varRetval = rsCategoryMap.Fields(lngCol).Value

rsCategoryMap.MoveNext

结束选择

结束选择


案例acLBGetColumnWidth

''每列应该有多少缇?

''(可选)


Case acLBGetFormat

''每列的格式是什么?

''(可选)


案例acLBEnd

''如果需要,可以清理(可选,除非你使用

''你想要记忆的数组ase)。


结束选择

映射= varRetval

结束功能


任何帮助将不胜感激。我还想知道

事件8和2是什么。我已经看了但是没有用....


干杯


青蛙

解决方案

The Frog写道:


大家好,


也许我在这里只是遗漏了一些简单的东西,但我似乎在A97中有一个带回调函数的问题,用于用值填充Listbox

。第一次使用回调函数(当

表单打开时)一切运行良好,每个人都很高兴。然后是

问题 - 值被添加到记录集(ADO),回调

函数用来填充列表框。


将新值添加到记录集后,

的显而易见的事情是对列表框使用requery方法,从而激活

回调函数,以及从理论上说,重新填充列表框的值为

。这不是正在发生的事情。事实上,在回调中发生的事件

序列甚至没有击中事件6

(acLBGetValue)或事件3(acLBGetRowCount),它就像这样...... 8-> 2


>> 8-> 9-> 0-> 2-> 1并在那里结束。不知何故,不知怎的,神奇地,即使没有



代码与任何这些情况下的数据填充有关,记录

出现在列表框中代码崩溃说

记录集是EOF或BOF ....


现在我让F8通过这个步骤,这里是另一个最好的b $ b好​​奇的事情:关闭代码窗口后,我再次得到EOF或BOF

消息并跳转到调试并猜测是什么?它在事件6尝试

来获取数据!我在这里疯了还是我错过了什么?b $ b完全,或者是我的A97我必须在这里决定用我的脑子来玩

?下面是回调函数代码的副本。

ADO记录集有两个字段,都是文本。哦是的,我正在尝试

将字段名称作为列标题放置(似乎工作正常)。


函数映射(ctl As Control, _

varId As Variant,lngRow As Long,lngCol As Long,_

intCode As Integer)As Variant


Dim varRetval作为Variant


选择案例intCode

案例acLBInitialize

''你能初始化吗?

如果rsCategoryMap.RecordCount 0然后

rsCategoryMap.MoveFirst

结束如果

varRetval = True


案例acLBOpen

''什么是唯一标识符?

varRetval =计时器


案例acLBGetRowCount

''有多少行?

如果rsCategoryMap.RecordCount = 0那么

varRetval = 1

Else
varRetval = rsCategoryMap.RecordCount + 1

rsCategoryMap.MoveFirst

结束如果


Case acLBGetColumnCount

''有多少列?

varRetval = rsCategoryMap.Fields.Count


Case acLBGetValue

''什么每行/每列的值是多少?

选择案例lngRow

案例(0)

varRetval = rsCategoryMap.Fields( lngCol).Name

Case Else

选择案例lngCol

案例(0)

varRetval = rsCategoryMap.Fields (lngCol).Value

Case Else

varRetval = rsCategoryMap.Fields(lngCol).Value

rsCategoryMap.MoveNext

结束选择

结束选择ct


Case acLBGetColumnWidth

''每列应该有多少缇?

''(可选)


Case acLBGetFormat

''每列的格式是什么?

''(可选)


Case acLBEnd

''如果需要,可以清理(可选,除非你使用

''一个你要释放内存的数组)。


结束选择

映射= varRetval

结束功能


任意帮助将不胜感激。我还想知道

事件8和2是什么。我一直在寻找但无济于事....


干杯


青蛙



我没有在Case acLBGetValue中使用过你的方法。你在其中移动了
movenexting。在我的所有代码中,它都是在init中完成的。


我可能有这样的东西。在OptionExplicit下

私有类型组合列表

strDesc为字符串

结束类型


然后

私有函数MyFillFunction(fld As Control,ID As Variant,row As

Variant,col As Variant,Code As Variant)As Variant

On Error Resume下一页

静态strRows()为ComboType

静态条目为整数


Dim varToHold As Variant

Dim ReturnVal As Variant


ReturnVal = Null


选择案例代码

案例acLBInitialize''初始化。

Dim rst记录集

条目= 0

ReDim保留strRows(参赛作品)


strRows(条目).strDesc ="(全部)"


Dim rst作为记录集

设置rst = Currentdb.OpenRecordset(" MyTable",dbopensnapshot)

做的不是rst.EOF

条目=条目+ 1

ReDim保留strRows(条目)

strRows (条目).strDesc = rst![描述]

rst.MoveNext

循环

rst.Close

设置rst = Nothing

ReturnVal = True

案例acLBOpen

ReturnVal =计时器

案例acLBGetRowCount''获取号码行

ReturnVal =条目+ 1

案例acLBGetColumnCount''获取列数。

ReturnVal = 1

Case acLBGetColumnWidth''列宽。

ReturnVal = -1''-1强制使用默认宽度。

Case acLBGetValue''获取数据。

ReturnVal = strRows(row).strDesc

Case acLBEnd''End。

Erase strRows

结束选择

FillInternalListBox = ReturnVal

结束函数

我喜欢使用Types来保存我的元素列表。


嗨沙拉,


感谢您的信息。我尝试了这个方法,但是对于我的列表框我不能完全像这样使用它,因为ADO记录集是一个

未绑定(构造)的记录集,并且初始化在

开始通过重置记录集来杀死任何存储的信息。

不幸的是它实际上并不基于任何特定的表。


我认为导致问题的原因是,在

问题上睡个好觉之后,列标题的建立令人心烦

行数,并且因此可能会更好地从列/

行中删除并简单地作为列位置上的标签。


所以这里的想法 - 记录集作为一个全局var已经

在表单打开之前调暗并设置,然后当表单打开时,

回调函数将被激活并且不返回

rowcount,因此没有记录。当用户更新数据(取自

表单上的其他选项并通过单击按钮添加)时,更新

记录集,调用requery方法列表框,

,理论上没有更多的EOF / BOF问题,因为行数将与bc $ b完全匹配记录计数。那个理论,我会告诉你

怎么回事。


我告诉你什么,我真的希望我能用更新的版本

访问这个 - 生活会简单得多......


干杯谢谢:-)


青蛙


青蛙写道:


嗨沙拉,


感谢您的信息。我尝试了这个方法,但是对于我的列表框我不能完全像这样使用它,因为ADO记录集是一个

未绑定(构造)的记录集,并且初始化在

开始通过重置记录集来杀死任何存储的信息。

不幸的是它实际上并不基于任何特定的表。


我认为导致问题的原因是,在

问题上睡个好觉之后,列标题的建立令人心烦

行数,并且因此可能会更好地从列/

行中删除并简单地作为列位置上的标签。


所以这里的想法 - 记录集作为一个全局var已经

在表单打开之前调暗并设置,然后当表单打开时,

回调函数将被激活并且不返回

rowcount,因此没有记录。当用户更新数据(取自

表单上的其他选项并通过单击按钮添加)时,更新

记录集,调用requery方法列表框,

,理论上没有更多的EOF / BOF问题,因为行数将与bc $ b完全匹配记录计数。那个理论,我会告诉你

怎么回事。


我告诉你什么,我真的希望我能用更新的版本

访问这个 - 生活会简单得多......


干杯谢谢:-)


青蛙



我提供了一些我使用的代码的基本版本。在我的初始化中我可能

有一个基本记录集,我克隆然后过滤和排序。我首先在表单的声明部分调暗了
clone。


Ex :(使用DAO)在声明部分中

Dim rst记录集


在列表框功能中

设置rstClone = rst.OpenRecordset

rstClone.Filter =。 ..

rstClone.Sort = ...


然后我在rstClone上处理记录计数并填充列表框

将rowitems转换为Type''d结构。


我需要在子程序中根据需要打开rst,因为数据经常更新。因为它已在声明

部分中声明,以后引用不是问题。


我不知道为什么你必须使用ADO如果引起问题。你

总能引用DAO记录集

Dim rst作为DAO.Recordset


祝你好好调试。


Hi all,

Maybe I am just missing something simple here, but I seem to have an
issue with a callback function in A97 that is used to fill a Listbox
with values. The first time the callback function is used (when the
form opens) all runs well and everyone is happy. Then comes the
problem - values are added to the recordset (ADO) that the callback
function uses to populate the listbox.

After the new values are added to the recordset, the obvious thing to
do is to use the requery method for the listbox, hence activating the
callback function, and in theory re-populating the listbox with values
all over again. This is not what is happening. In fact the event
sequence that is taking place in the callback doesnt even hit event 6
(acLBGetValue) or event 3 (acLBGetRowCount), it goes like this... 8->2-

>8->9->0->2->1 and ends there. Still, somehow, magically, even with no

code relating to data population in any of these cases the records
appear in the listbox BUT the code crashes out saying that the
recordset is eith EOF or BOF....

Now I have F8 stepped my way through this, and here is the other most
curious thing: After I close the code window I get the EOF or BOF
message again and jump to debug and guess what? Its in event 6 trying
to get the data! Am I going insane here or I have I missed something
completely, or is my A97 I have to work with here deciding to play
with my mind? A copy of the code for the callback function is below.
The ADO recordset has two fields, both text. Oh yeah, and I am trying
to place the field names as the column headers (seems to work okay).

Function Mapped(ctl As Control, _
varId As Variant, lngRow As Long, lngCol As Long, _
intCode As Integer) As Variant

Dim varRetval As Variant

Select Case intCode
Case acLBInitialize
'' Could you initialize?
If rsCategoryMap.RecordCount 0 Then
rsCategoryMap.MoveFirst
End If
varRetval = True

Case acLBOpen
'' What''s the unique identifier?
varRetval = Timer

Case acLBGetRowCount
'' How many rows are there to be?
If rsCategoryMap.RecordCount = 0 Then
varRetval = 1
Else
varRetval = rsCategoryMap.RecordCount + 1
rsCategoryMap.MoveFirst
End If

Case acLBGetColumnCount
'' How many columns are there to be?
varRetval = rsCategoryMap.Fields.Count

Case acLBGetValue
'' What''s the value in each row/column to be?
Select Case lngRow
Case (0)
varRetval = rsCategoryMap.Fields(lngCol).Name
Case Else
Select Case lngCol
Case (0)
varRetval = rsCategoryMap.Fields(lngCol).Value
Case Else
varRetval = rsCategoryMap.Fields(lngCol).Value
rsCategoryMap.MoveNext
End Select
End Select

Case acLBGetColumnWidth
'' How many twips wide should each column be?
'' (optional)

Case acLBGetFormat
'' What''s the format for each column to be?
'' (optional)

Case acLBEnd
'' Just clean up, if necessary (optional, unless you use
'' an array whose memory you want to release).

End Select
Mapped = varRetval
End Function

Any help would be greatly appreciated. I would also like to know what
events 8 and 2 are. I have gone looking but to no avail....

Cheers

The Frog

解决方案

The Frog wrote:

Hi all,

Maybe I am just missing something simple here, but I seem to have an
issue with a callback function in A97 that is used to fill a Listbox
with values. The first time the callback function is used (when the
form opens) all runs well and everyone is happy. Then comes the
problem - values are added to the recordset (ADO) that the callback
function uses to populate the listbox.

After the new values are added to the recordset, the obvious thing to
do is to use the requery method for the listbox, hence activating the
callback function, and in theory re-populating the listbox with values
all over again. This is not what is happening. In fact the event
sequence that is taking place in the callback doesnt even hit event 6
(acLBGetValue) or event 3 (acLBGetRowCount), it goes like this... 8->2-

>>8->9->0->2->1 and ends there. Still, somehow, magically, even with no


code relating to data population in any of these cases the records
appear in the listbox BUT the code crashes out saying that the
recordset is eith EOF or BOF....

Now I have F8 stepped my way through this, and here is the other most
curious thing: After I close the code window I get the EOF or BOF
message again and jump to debug and guess what? Its in event 6 trying
to get the data! Am I going insane here or I have I missed something
completely, or is my A97 I have to work with here deciding to play
with my mind? A copy of the code for the callback function is below.
The ADO recordset has two fields, both text. Oh yeah, and I am trying
to place the field names as the column headers (seems to work okay).

Function Mapped(ctl As Control, _
varId As Variant, lngRow As Long, lngCol As Long, _
intCode As Integer) As Variant

Dim varRetval As Variant

Select Case intCode
Case acLBInitialize
'' Could you initialize?
If rsCategoryMap.RecordCount 0 Then
rsCategoryMap.MoveFirst
End If
varRetval = True

Case acLBOpen
'' What''s the unique identifier?
varRetval = Timer

Case acLBGetRowCount
'' How many rows are there to be?
If rsCategoryMap.RecordCount = 0 Then
varRetval = 1
Else
varRetval = rsCategoryMap.RecordCount + 1
rsCategoryMap.MoveFirst
End If

Case acLBGetColumnCount
'' How many columns are there to be?
varRetval = rsCategoryMap.Fields.Count

Case acLBGetValue
'' What''s the value in each row/column to be?
Select Case lngRow
Case (0)
varRetval = rsCategoryMap.Fields(lngCol).Name
Case Else
Select Case lngCol
Case (0)
varRetval = rsCategoryMap.Fields(lngCol).Value
Case Else
varRetval = rsCategoryMap.Fields(lngCol).Value
rsCategoryMap.MoveNext
End Select
End Select

Case acLBGetColumnWidth
'' How many twips wide should each column be?
'' (optional)

Case acLBGetFormat
'' What''s the format for each column to be?
'' (optional)

Case acLBEnd
'' Just clean up, if necessary (optional, unless you use
'' an array whose memory you want to release).

End Select
Mapped = varRetval
End Function

Any help would be greatly appreciated. I would also like to know what
events 8 and 2 are. I have gone looking but to no avail....

Cheers

The Frog

I haven''t ever used your method in Case acLBGetValue. You are
movenexting within it. In all my code, it''s done in the init.

I might have something like this. Under OptionExplicit
Private Type ComboList
strDesc As String
End Type

Then
Private Function MyFillFunction(fld As Control, ID As Variant, row As
Variant, col As Variant, Code As Variant) As Variant
On Error Resume Next
Static strRows() As ComboType
Static Entries As Integer

Dim varToHold As Variant
Dim ReturnVal As Variant

ReturnVal = Null

Select Case Code
Case acLBInitialize '' Initialize.
Dim rst As Recordset
Entries = 0
ReDim Preserve strRows(Entries)

strRows(Entries).strDesc = "(All)"

Dim rst As Recordset
Set rst = Currentdb.OpenRecordset("MyTable",dbopensnapshot)
Do While Not rst.EOF
Entries = Entries + 1
ReDim Preserve strRows(Entries)
strRows(Entries).strDesc = rst![Description]
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
ReturnVal = True
Case acLBOpen
ReturnVal = Timer
Case acLBGetRowCount '' Get number of rows
ReturnVal = Entries + 1
Case acLBGetColumnCount '' Get number of columns.
ReturnVal = 1
Case acLBGetColumnWidth '' Column width.
ReturnVal = -1 '' -1 forces use of default width.
Case acLBGetValue '' Get data.
ReturnVal = strRows(row).strDesc
Case acLBEnd '' End.
Erase strRows
End Select
FillInternalListBox = ReturnVal
End Function
I like using Types to hold my list of elements.


Hi Salad,

Thanks for the info. I gave this method a try, but for my listbox I
cannot use it exactly like this because the ADO recordset is an
unbound (constructed) recordset, and the re-initialisation at the
start kills any stored information by resetting the recordset.
Unfortunately it is not actually based on any particular table.

What I believe causes the issue, after a good night sleep on the
matter, is that the establishment of the column headers is upsetting
the rowcount, and as such might be better removed from the columns /
rows and done simply as labels over the column positions.

So here''s the thinking - keep the recordset as a global var already
dimmed and set up before the form opens, then when the form opens the
callback function will be activated and return nothing for the
rowcount and hence no records. When the user updates data (taken from
other selections on the form and added by a click of a button), the
recordset is updated, the requery method is called for the listbox,
and in theory there are no more EOF / BOF issues as the rowcount will
match exactly the recordcount. Thats the theory, I will let you know
how it goes.

I tell you what, I really wish I were able to use a newer version of
access for this - life would be so much simpler......

Cheers and thanks :-)

The Frog


The Frog wrote:

Hi Salad,

Thanks for the info. I gave this method a try, but for my listbox I
cannot use it exactly like this because the ADO recordset is an
unbound (constructed) recordset, and the re-initialisation at the
start kills any stored information by resetting the recordset.
Unfortunately it is not actually based on any particular table.

What I believe causes the issue, after a good night sleep on the
matter, is that the establishment of the column headers is upsetting
the rowcount, and as such might be better removed from the columns /
rows and done simply as labels over the column positions.

So here''s the thinking - keep the recordset as a global var already
dimmed and set up before the form opens, then when the form opens the
callback function will be activated and return nothing for the
rowcount and hence no records. When the user updates data (taken from
other selections on the form and added by a click of a button), the
recordset is updated, the requery method is called for the listbox,
and in theory there are no more EOF / BOF issues as the rowcount will
match exactly the recordcount. Thats the theory, I will let you know
how it goes.

I tell you what, I really wish I were able to use a newer version of
access for this - life would be so much simpler......

Cheers and thanks :-)

The Frog

I provided a very basic version of some code I use. In my Init I might
have a basic recordset that I clone then filter and sort. My rst that I
clone is dimmed in the declarations section of the form.

Ex: (using DAO) in the declarations section
Dim rst As Recordset

In the Listbox function
Set rstClone = rst.OpenRecordset
rstClone.Filter = ...
rstClone.Sort = ...

And then I process on rstClone the record count and stuff the listbox
rowitems into a Type''d structure.

I have the need to open the rst as needed in a subroutine as the data
gets updated often. Since it''s been declared in the Declarations
section that is not a problem in referencing later.

I''m not sure why you must use ADO if that is causing problems. You
could always reference a DAO recordset with
Dim rst As DAO.Recordset

Good luck in your debugging.


这篇关于A97中的回调函数重新查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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