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