ListBox Selection hard to recover

mercredi 18 mars 2015

I have a setup where a selection from a Listbox fetches a record. I am using the well-known method of setting up a recordset clone and on finding the record goes to it via the clone's bookmark, something like...




Code:



If Nz(DLookup("EEID", "tblPayPeriod", Criteria)) <> 0 Then

' record exists - get it

Set rst = Me.RecordsetClone

rst.FindFirst "EEID=" & eid & " AND PPDate = #" & Format(txtPPDate, "mm/dd/yyyy") & "#"

If Not rst.NoMatch Then

Me.Undo

Me.Bookmark = rst.Bookmark

rst.Close

Set rst = Nothing

....

End If

Else....



If the record is not found (ie the employee does not have a record for the pay period) it is created and initialized. Works well with one little irritating glitch. The routine 'loses' the selection in the Emplist which provides a useful visual clue to the user of the program. Through some testing I feel now sure it is the switch of the bookmarks that causes the hiccup. The Emplist keeps its ListIndex property but it will not allow setting the Selected record. Requerying the ListBox explicitly does work in one setting but not in another !!! I finally found a workaround for resetting the selection bar by placing the requery in an OnTimer event like




Code:



Private Sub Form_Timer()

TimerInterval = 0

With EmpList

.Requery

.Selected(FindListIndex(Me!EEID)) = True

End With

End Sub



but surely this is ugly. Anyone has any insight into this ? Would be much appreciated.



Best,

Jiri

ListBox Selection hard to recover

0 commentaires:

Enregistrer un commentaire

Labels