ListBox in Excel retrieve Data from Access Database Issue

bharatvly

Board Regular
Joined
Jun 3, 2014
Messages
61
Hello Folks!
I am facing an issue with the below. It looks perfect to be but it doesn't work the way I expected it to work.
What this code does is - retrieves data from access database and populates it in a Listbox inside a userform in excel.
What it doesn't do - It populates the data only in the 1st row in the Listbox although the data retrieved from the database is of more than 1 row. Any help please? There is something wrong with the code and I can't figure out.

cnn.Open "Provider = Microsoft.ACE.oledb.12.0; data source= " & ThisWorkbook.Path & "\" & "DTT_Database.accdb" & ";Jet OLEDB:Database Password=$bJa$FromGD4@;"
qry = "select * from task_tracker;"
rst.Open qry, cnn, adOpenKeyset, adLockOptimistic
rst.MoveFirst
With UserForm1.ListBox1
Do
.AddItem
.List(0, 0) = rst.Fields("start_time").Value
.List(0, 1) = rst.Fields("login_id").Value
rst.MoveNext
Loop Until rst.EOF
End With
rst.MoveFirst
rst.Close
cnn.Close
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Maybe try using

Do
.AddItem = rst.Fields("start_time").Value
.Column(1) = rst.Fields("login_id").Value
rst.MoveNext
Loop Until rst.EOF

since

.List(0, 0) has you stuck on the first row regardless of the additem

if you want to use list

.List(.Listcount-1, 0)
etc
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,415
Members
448,960
Latest member
AKSMITH

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