将第2列的多列列表框结果拆分为Txt框 [英] Split Muti Column Listbox results of column 2 to a Txt Box

查看:73
本文介绍了将第2列的多列列表框结果拆分为Txt框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助,

我是新的"编码员"并且已经能够基于网络搜索和论坛完成很多工作,但我很困难!!!!!

I am a new "coder" and have been able to accomplish a lot based on web searches and forums but i am Stuck!!!!!

我有一个多列列表框,可以从Access数据库中提取数据我需要将结果第二列中的选定结果信息分隔到列表框选择旁边的文本框中。

I have a multi column list box that pulls data from an Access Data base and I need to seperate the selected result info from the second column of the results into a text box next to the list box selection.

我希望第一列在列表框中保持选中状态但是在附近的文本框中显示的第二列

I want the first column to stay selected in the list box but the second column to display in a nearby text box

这里是我目前拥有的代码

here is the code I currently have

Private Sub UserForm_Initialize()



Dim db As DAO.Database

Dim rs As DAO.Recordset

Dim NoOfRecords As Long

  

 设置db = OpenDatabase(" J:\DatabaseMay13.mdb"))
 设置rs = db.OpenRecordset(" SELECT * FROM Sheet1")

 使用rs

    .MoveLast

    NoOfRecords = .RecordCount

    .MoveFirst

 结束与$
  LBsurety.ColumnCount = 2

  LBsurety.Column = rs.GetRows(NoOfRecords)

  LBsurety.ColumnWidths =" 250; 50"

  rs.Close

  db.Close

 设置rs =无结果
 设置db = Nothing

lbl_Exit:

 退出子目标

结束子

Private Sub UserForm_Initialize()

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
  
  Set db = OpenDatabase("J:\DatabaseMay13.mdb")
  Set rs = db.OpenRecordset("SELECT * FROM Sheet1")
  With rs
    .MoveLast
    NoOfRecords = .RecordCount
    .MoveFirst
  End With
  LBsurety.ColumnCount = 2
  LBsurety.Column = rs.GetRows(NoOfRecords)
  LBsurety.ColumnWidths = "250;50"
  rs.Close
  db.Close
  Set rs = Nothing
  Set db = Nothing
lbl_Exit:
  Exit Sub
End Sub




推荐答案


我希望第一列在列表框中保持选中状态,但第二列要在附近的文本框中显示

I want the first column to stay selected in the list box but the second column to display in a nearby text box

您好,

欢迎使用Excel for Developers论坛。

Welcome to Excel for Developers forum.

根据您的描述,您可以使用ListBox.ListIndex属性来获取当前所选项目的索引(从0开始)。然后使用ListBox.List(index,index)获取要在另一个文本框中显示的文本:

According to your description, you can use ListBox.ListIndex Property to get the index of currently selected item (starts from 0). And then use ListBox.List(index, index) to get the text you want to display in another text box:

Private Sub ListBox1_Change()    Dim selectedIndex As Variant    selectedIndex = ListBox1.ListIndex    TextBox1.Text = ListBox1.List(selectedIndex, 1)End Sub

将此代码段放在列表框的Change事件中。

Put this code snippet in the Change event of the list box.

问候,


这篇关于将第2列的多列列表框结果拆分为Txt框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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