Ms访问中的列表框 [英] Listbox in Ms access

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

问题描述

我可以通过使用带有以下代码的组合框将记录存储在数据库中.此处选择单个零件编号,零件编号相关数据存储在 DB 表中.

I can store records in the DB by using combobox with the following code. Here single part number is selected and partnumber related data is stored in the DB table.

但是我想要 Listbox 的代码...当我选择多个零件编号时...如何存储在 DB 表中?

But I want the code for Listbox...When I select multiple partnumbers ..how can I store in the DB table?

Case "Pn ADDED to Wrapper", _
            "Pn REMOVED from Wrapper"
            If Me!PartNumber <> "All" And Me!PartNumber <> "Select" Then ' a proper part number has been selected in combo box
                strNewSq5 = _
                    "INSERT INTO tblTmpEventLog (TrackingNumber,PartNumber,PartNumberChgLvl,EnteredBy,EventTypeSelected,EventDate)"
                strNewSq5 = strNewSq5 & " VALUES ('" & tempTrackingNumber & "','" & _
                    tempPartNumber & "','" & _
                    tempPartNumberChgLvl & "','" & _
                    tempEnteredBy & "','" & _
                    tempEventTypeSelected & "'," & _
                    "#" & Forms!frmEventLog_Input.EventDate & "#)"
                dbs.Execute strNewSq5, dbFailOnError

                TrnsfTmpEventToEventLog
                Else
                        displayMsgBox = MsgBox("A single part number must be specified. Please correct.", vbCritical, "System Error")
                Exit Sub
                End If

推荐答案

需要对选中的项进行迭代并一一存储:

You need to iterate over the selected items and store them one by one:

MS Access 2007 - 循环浏览列表框中的值以获取 SQL 语句的 ID

编辑重新评论

您没有为详细答案提供足够的信息,但这里有一些可能会有所帮助的注释.

You do not provide sufficient information for a detailed answer, but here are some notes that may help.

For Each itm In Me.NameOfListBox.ItemsSelected
      If Instr("All,Select",Me.NameOfListBox.Column(0, itm) )=0 Then 
           '' a proper part number has been selected in list box

           '' Me.NameOfListBox.Column(0, itm) is the column (zero in this example
           '' and row (itm) of the selected item in the list box. If it is the 
           '' part number, then you might like to say:

           '' tempPartNumber = Me.NameOfListBox.Column(0, itm)

           strNewSq5 = "INSERT INTO tblTmpEventLog " & _ 
                    "(TrackingNumber,PartNumber,PartNumberChgLvl,EnteredBy," & _
                    "EventTypeSelected,EventDate)"
           strNewSq5 = strNewSq5 & " VALUES ('" & tempTrackingNumber & "','" & _
                    tempPartNumber & "','" & _
                    tempPartNumberChgLvl & "','" & _
                    tempEnteredBy & "','" & _
                    tempEventTypeSelected & "'," & _
                    "#" & Forms!frmEventLog_Input.EventDate & "#)"
          dbs.Execute strNewSq5, dbFailOnError

          TrnsfTmpEventToEventLog
    Else
         ''Do not insert
    End If
Next

这篇关于Ms访问中的列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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