Inserting non visible columns in listbox to table

inkbird1

Board Regular
Joined
Apr 21, 2020
Messages
51
Hi, I have listbox with student names.
I want to add a record to a table including the listbox's non visible items as well as the student's name

VBA Code:
Private Sub btn_Create_Click()
''Dim strSQL        As String
  Dim db            As DAO.Database
  Dim rs            As DAO.Recordset
  Dim ctl           As Control
  Dim varItem       As Variant

  Set db = CurrentDb()
  Set rs = db.OpenRecordset("Tbl_placements", dbOpenDynaset, dbAppendOnly)

  'add selected value(s) to table
  Set ctl = Me.lstSecond
  For Each varItem In ctl.ItemsSelected
    rs.AddNew
    rs!studentID = ctl.ItemData(varItem)
    rs!EmployeeID = [COLOR=rgb(226, 80, 65)]**SECOND COLUMN OF LIST BOX**[/COLOR]
    rs!TradingAs = cbo_provider
    rs!StartDate = txt_startdate
    rs!EndDate = txt_enddate

    rs.Update
  Next varItem
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Something like this should get you the second column of listbox
Me.ctl.Column(1, varItem)
or
Me.lstSecond.Column(1, varItem)
I don't think I'd bother creating ctl object for this. Would just use Me.lstSecond reference.

List is zero based, so first column is 0
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,850
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top