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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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