View Full Version : Listbox fill via recordset
malleshg24
08-23-2021, 12:34 AM
Hi Team,
I am uploading recordset value to listbox using adbodb. library.
I am using loop here.
Can we use listbox1.rowsource = rs
Attached file
Thanks
mg
See: https://www.snb-vba.eu/VBA_ADODB_recordset_en.html#L_12.2.0.2
arnelgp
08-23-2021, 04:12 AM
can you not Open the workbook using Automation.
dim wb as workbook
dim sh as worksheet
set wb = application.workbooks.open(ThisWorkbook.Path & "\Movies.xlsx")
set sh=wb.worksheets(1)
Tom Jones
08-23-2021, 05:30 AM
@arnelgp (http://www.vbaexpress.com/forum/member.php?74556-arnelgp) ,
How "can you not Open the workbook" if you use "application.workbooks.open(....."
arnelgp
08-23-2021, 05:44 AM
something like this:
Private Sub test()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSH As Excel.Worksheet
Dim i As Integer
'create new instance of excel
Set oXL = New Excel.Application
'open the workbook
Set oWB = oXL.Workbooks.Open(ThisWorkbook.Path & "\Movies.xlsx")
'set the sheet to work with
Set oSH = oWB.Sheets(1)
With oSH
'clear the listbox
Me.ListBox1.Clear
'add items to listbox
For i = 1 To .Range("A1").SpecialCells(xlCellTypeLastCell).Row
Me.ListBox1.AddItem .Range("A" & i)
Next
End With
'destroy the objects
Set oSH = Nothing
oWB.Close savechanges:=False
Set oWB = Nothing
oXL.Quit
Set oXL = Nothing
End Sub
@arnel
Don't you read other contributions ?
arnelgp
08-23-2021, 06:40 AM
you direct that to the OP.
this is a simple automation where the source is
also a workbook (not a database).
although recordset is universal, still using
automation does not require thorough knowledge
of recordset.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.