是否进入VBA有Listbox.List方法为Excel VBA有 [英] Does access VBA has Listbox.List method as excel VBA has
本文介绍了是否进入VBA有Listbox.List方法为Excel VBA有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在写code在列表框项目的访问VBA来上下移动。需要使用的.List物业的访问。但是,它抛出一个错误说没有一种方法或成员发现。任何与更换的.List的方法?研究这个超过4天。 私人小组cmdUP_Click()
暗淡我只要
昏暗leaveAlone由于布尔
昏暗的POS机只要
昏暗的温度作为字符串
POS = 0
随着Me.lbfNames
对于i = 0到.ListCount - 1
leaveAlone =假
如果.Selected(ⅰ)然后
如果我= POS然后
leaveAlone = TRUE
结束如果
POS = POS + 1
如果leaveAlone = false,那么
临时= .RowSource(ⅰ - 1)
.RowSource(I - 1)= .RowSource(我)我来代替行源之前的.List
.RowSource(ⅰ)=温度
.ListIndex = I - 1
.Selected(I)= FALSE
.Selected(I - 1)=真
结束如果
结束如果
下一个
结束与
解决方案
我已经想通了,如何做到这一点的访问。但设置列表框中多选属性设置为无。
下移
私人小组cmdDown_Click()
昏暗STEXT作为字符串
昏暗iIndex作为整数
昏暗bottomLimit作为整数
iIndex = lbfNames.ListIndex
bottomLimit = lbfNames.ListCount - 1
检查:只有进行,如果有一个选定的项目
如果lbfNames.ListCount> 1然后
如果iIndex> = bottomLimit然后
MSGBOX(不能移动该项目下任何进一步的。)
退出小组
结束如果
保存项目的文本和项目indexvalue
STEXT = lbfNames.Column(0,iIndex)
如果iIndex< bottomLimit然后
lbfNames.RemoveItem iIndex
地方项目早在新的位置
lbfNames.AddItem STEXT,iIndex + 1
结束如果
如果你一直选择的项目
你可以保持由pressing移动它btnMoveDown
lbfNames.Selected(iIndex + 1)=真
iIndex = iIndex + 1
结束如果
结束小组
向上
私人小组cmdUP_Click()
昏暗STEXT作为字符串
昏暗iIndex作为整数
iIndex = lbfNames.ListIndex
REDIM iIndex(0〜10)
检查:只有进行,如果有一个选定的项目
如果lbfNames.ListCount> 1然后
索引0是不能移动了顶部的项目!
如果iIndex&所述; = 0。然后
MSGBOX(不能移动该项目的任何更高。)
退出小组
结束如果
如果iIndex = -1或lbfNames.ListCount> 1然后
保存项目的文本和项目indexvalue
STEXT = lbfNames.Column(0,iIndex)
lbfNames.RemoveItem iIndex
地方项目回新位置
lbfNames.AddItem STEXT,iIndex - 1
如果你一直选择的项目
你可以保持由pressing cmdUp移动它
lbfNames.Selected(iIndex - 1)=真
iIndex = iIndex - 1
结束如果
结束小组
I'm writing code in access vba for the list box items to move up and down. Needs to use .List Property in access . But it throws an error says no method or member found. Any replace method with .List ? Researching on this more than 4 days. Private Sub cmdUP_Click()
Dim i As Long
Dim leaveAlone As Boolean
Dim pos As Long
Dim Temp As String
pos = 0
With Me.lbfNames
For i = 0 To .ListCount - 1
leaveAlone = False
If .Selected(i) Then
If i = pos Then
leaveAlone = True
End If
pos = pos + 1
If leaveAlone = False Then
Temp = .RowSource(i - 1)
.RowSource(i - 1) = .RowSource(i) ' before i used .List instead of rowsource
.RowSource(i) = Temp
.ListIndex = i - 1
.Selected(i) = False
.Selected(i - 1) = True
End If
End If
Next
End With
解决方案
I've figured that out, how to do it in access. But set list box Multiselect property to 'None'.
Moving Down
Private Sub cmdDown_Click()
Dim sText As String
Dim iIndex As Integer
Dim bottomLimit As Integer
iIndex = lbfNames.ListIndex
bottomLimit = lbfNames.ListCount - 1
'check: only proceed if there is a selected item
If lbfNames.ListCount > 1 Then
If iIndex >= bottomLimit Then
MsgBox ("Can not move the item down any further.")
Exit Sub
End If
'save items text and items indexvalue
sText = lbfNames.Column(0, iIndex)
If iIndex < bottomLimit Then
lbfNames.RemoveItem iIndex
'place item back in new position
lbfNames.AddItem sText, iIndex + 1
End If
'if you keep that item selected
'you can keep moving it by pressing btnMoveDown
lbfNames.Selected(iIndex + 1) = True
iIndex = iIndex + 1
End If
End Sub
Moving up
Private Sub cmdUP_Click()
Dim sText As String
Dim iIndex As Integer
iIndex = lbfNames.ListIndex
' ReDim iIndex(0 To 10)
'check: only proceed if there is a selected item
If lbfNames.ListCount > 1 Then
'index 0 is top item which can't be moved up!
If iIndex <= 0 Then
MsgBox ("Can not move the item up any higher.")
Exit Sub
End If
' If iIndex = -1 Or lbfNames.ListCount > 1 Then
'save items text and items indexvalue
sText = lbfNames.Column(0, iIndex)
lbfNames.RemoveItem iIndex
'place item back on new position
lbfNames.AddItem sText, iIndex - 1
'if you keep that item selected
'you can keep moving it by pressing cmdUp
lbfNames.Selected(iIndex - 1) = True
iIndex = iIndex - 1
End If
End Sub
这篇关于是否进入VBA有Listbox.List方法为Excel VBA有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文