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来保存我的元素列表。 我提供了一些我使用的代码的基本版本。在我的初始化中我可能 有一个基本记录集,我克隆然后过滤和排序。我首先在表单的声明部分调暗了 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 anissue with a callback function in A97 that is used to fill a Listboxwith values. The first time the callback function is used (when theform opens) all runs well and everyone is happy. Then comes theproblem - values are added to the recordset (ADO) that the callbackfunction uses to populate the listbox. After the new values are added to the recordset, the obvious thing todo is to use the requery method for the listbox, hence activating thecallback function, and in theory re-populating the listbox with valuesall over again. This is not what is happening. In fact the eventsequence that is taking place in the callback doesnt even hit event 6(acLBGetValue) or event 3 (acLBGetRowCount), it goes like this... 8->2-code relating to data population in any of these cases the recordsappear in the listbox BUT the code crashes out saying that therecordset is eith EOF or BOF.... Now I have F8 stepped my way through this, and here is the other mostcurious thing: After I close the code window I get the EOF or BOFmessage again and jump to debug and guess what? Its in event 6 tryingto get the data! Am I going insane here or I have I missed somethingcompletely, or is my A97 I have to work with here deciding to playwith 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 tryingto 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 intCodeCase acLBInitialize'' Could you initialize?If rsCategoryMap.RecordCount 0 ThenrsCategoryMap.MoveFirstEnd IfvarRetval = True Case acLBOpen'' What''s the unique identifier?varRetval = Timer Case acLBGetRowCount'' How many rows are there to be?If rsCategoryMap.RecordCount = 0 ThenvarRetval = 1ElsevarRetval = rsCategoryMap.RecordCount + 1rsCategoryMap.MoveFirstEnd 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 lngRowCase (0)varRetval = rsCategoryMap.Fields(lngCol).NameCase ElseSelect Case lngColCase (0)varRetval = rsCategoryMap.Fields(lngCol).ValueCase ElsevarRetval = rsCategoryMap.Fields(lngCol).ValuersCategoryMap.MoveNextEnd SelectEnd 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 SelectMapped = varRetvalEnd Function Any help would be greatly appreciated. I would also like to know whatevents 8 and 2 are. I have gone looking but to no avail.... Cheers The Frog 解决方案 code relating to data population in any of these cases the recordsappear in the listbox BUT the code crashes out saying that therecordset is eith EOF or BOF....Now I have F8 stepped my way through this, and here is the other mostcurious thing: After I close the code window I get the EOF or BOFmessage again and jump to debug and guess what? Its in event 6 tryingto get the data! Am I going insane here or I have I missed somethingcompletely, or is my A97 I have to work with here deciding to playwith 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 tryingto 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 SelectMapped = varRetvalEnd FunctionAny help would be greatly appreciated. I would also like to know whatevents 8 and 2 are. I have gone looking but to no avail....CheersThe Frog I haven''t ever used your method in Case acLBGetValue. You aremovenexting within it. In all my code, it''s done in the init. I might have something like this. Under OptionExplicitPrivate Type ComboListstrDesc As StringEnd Type ThenPrivate Function MyFillFunction(fld As Control, ID As Variant, row AsVariant, col As Variant, Code As Variant) As VariantOn Error Resume NextStatic strRows() As ComboTypeStatic Entries As Integer Dim varToHold As VariantDim ReturnVal As Variant ReturnVal = Null Select Case CodeCase acLBInitialize '' Initialize.Dim rst As RecordsetEntries = 0ReDim Preserve strRows(Entries) strRows(Entries).strDesc = "(All)" Dim rst As RecordsetSet rst = Currentdb.OpenRecordset("MyTable",dbopensnapshot)Do While Not rst.EOFEntries = Entries + 1ReDim Preserve strRows(Entries)strRows(Entries).strDesc = rst![Description]rst.MoveNextLooprst.CloseSet rst = NothingReturnVal = TrueCase acLBOpenReturnVal = TimerCase acLBGetRowCount '' Get number of rowsReturnVal = Entries + 1Case acLBGetColumnCount '' Get number of columns.ReturnVal = 1Case acLBGetColumnWidth '' Column width.ReturnVal = -1 '' -1 forces use of default width.Case acLBGetValue '' Get data.ReturnVal = strRows(row).strDescCase acLBEnd '' End.Erase strRowsEnd SelectFillInternalListBox = ReturnValEnd FunctionI like using Types to hold my list of elements.I provided a very basic version of some code I use. In my Init I mighthave a basic recordset that I clone then filter and sort. My rst that Iclone is dimmed in the declarations section of the form. Ex: (using DAO) in the declarations sectionDim rst As Recordset In the Listbox functionSet rstClone = rst.OpenRecordsetrstClone.Filter = ...rstClone.Sort = ... And then I process on rstClone the record count and stuff the listboxrowitems into a Type''d structure. I have the need to open the rst as needed in a subroutine as the datagets updated often. Since it''s been declared in the Declarationssection that is not a problem in referencing later. I''m not sure why you must use ADO if that is causing problems. Youcould always reference a DAO recordset withDim rst As DAO.Recordset Good luck in your debugging. 这篇关于A97中的回调函数重新查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 04:15