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
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