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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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