Excel DAO listbox refresh issues

tark221

New Member
Joined
Apr 11, 2013
Messages
19
Hi All,

I have the below code attached to a button, when I click the button it runs the code below to update the record and then the code below that to populate the listbox. For some reason the listbox only updates if I click the button twice, so strange. Any ideas?

Code:
Sub UpdateRecord
Dim db As Dao.Database, rec As Dao.RecordsetDim strSQL As StringDim x As String
Set db = OpenDatabase(lbPath.Caption)strSQL = "SELECT * FROM tbl_INPUT WHERE [ID] = " & lbWorkload.Column(0)Set rec = db.OpenRecordset(strSQL, dbOpenDynaset, dbEditAdd)With rec.MoveFirst.Edit![Pause] = "Pause"![PauseLog] = Now().UpdateEnd Withrec.Close
Call PopulateListbox
End Sub

Code:
Sub PopululateListbox
mdbPath = frmHOME.lbPath.CaptionstrCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbPath & ";"Dim i As VariantDim cn      As New ADODB.ConnectionDim rs      As New ADODB.RecordsetDim MyArray As VariantDim sSQL    As StringOn Error Resume Nextcn.Open strConsSQL = "SELECT * from qryLast WHERE Username = " & "'" & Environ("Username") & "'"rs.Open sSQL, cnrs.MoveFirstWith frmHOME.lbWorkload.Clear.ColumnCount = 9Do While Not rs.EOF.AddItem.List(i, 0) = rs.Fields(0).List(i, 1) = rs.Fields(1).List(i, 2) = rs.Fields(2).List(i, 3) = rs.Fields(3).List(i, 4) = rs.Fields(4).List(i, 5) = rs.Fields(5).List(i, 6) = rs.Fields(6).List(i, 7) = rs.Fields(7).List(i, 8) = rs.Fields(8)i = i + 1rs.MoveNextLoopEnd Withrs.Closecn.CloseSet rs = NothingSet cn = NothingEnd Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,204
Messages
6,170,728
Members
452,353
Latest member
strainu

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