Accessible List

I can store records in a database using combobox with the following code. Here, the number of one part is selected, and the data associated with it is stored in the database table.

But I want code for a Listbox ... When I select multiple partnumbers .. how can I save to a 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 
0
source share
1 answer

You need to iterate over the selected elements and store them in turn:

MS Access 2007 - Enumerating Values ​​in a List Box to Capture an Identifier for an SQL Statement

EDIT re comment

You do not provide enough information for a detailed answer, but here are some notes that might 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 
0
source

Source: https://habr.com/ru/post/1383908/


All Articles