Listbox multiselect

R

Rick Humphrey

HI-
I'm working in Access 2000 with a List box that is inteneded to look up a
record on the form. I have MultiSelect property set to 'None' . For some
reason the ListBox is behaiving as if MultiSelect were true... IT never
release the previous selection which remains highlighted. This strange
behaivor then somehow cause some strange things in memory to occur.. here is
th forms code which I thought pretty simple....Option Compare Database, I
suspect there must be some method I am missing that would clear the previous
selection.... I would think it appropriate for that method to be executed in
the form.current procedure, can anyone help me to eliminate this odd
behaviour?

Thanks,

Rick

Private Sub Form_Load()
DoCmd.Maximize
End Sub

Private Sub Form_Current()
If Form.NewRecord = True Then
'new record
Unit = CInt(Forms!menuform.UnitLabel.Caption)
Else
'existing record
ReportsListBox.Value = ReportID
'some method here
End If
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
'MsgBox "validate"

Dim sErr As String
sErr = ""
Cancel = False
If IsNull(ReportName) Then sErr = sErr & "* Report Name is Req'd" & vbCrLf
If IsNull(Unit) Then sErr = sErr & "* Unit is Req'd" & vbCrLf
If IsNull(DateOfFailure) Then sErr = sErr & "* Date of Failure is Req'd"
& vbCrLf
If IsNull(PreparedBy) Then sErr = sErr & "* Prepared By is Req'd" & vbCrLf
If IsNull(DatePreparedBy) Then sErr = sErr & "* Date Prepared By is
Req'd" & vbCrLf

If VBA.Len(sErr) > 0 Then
ValSumLabel.Caption = sErr
Cancel = True
Else
ValSumLabel.Caption = ""
Cancel = False
End If

End Sub

Private Sub Form_AfterUpdate()
' MsgBox "requery Listbox"
ReportsListBox.Requery
End Sub

Private Sub ReportsListBox_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ReportID] = " & Str(Me![ReportsListBox])
Me.Bookmark = rs.Bookmark
End Sub
 
R

rs0905

This problem is odd, but maybe this would work to clear the previous
selection (placing this code before the point that you set the new selection
in the listbox):

Dim intCurrentRow as Integer

For intCurrentRow = 0 To listbox.ListCount - 1
If listbox.Selected(intCurrentRow) Then
Listbox.Selected(intCurrentRow) = False
End If
Next intCurrentRow

This would loop through each of the rows in the listbox, and for each row
that is selected, it would "unselect" it. This is a guess since I can't
recreate your problem, but hopefully it will help!
 
L

Linq Adams via AccessMonster.com

"IT never release the previous selection which remains highlighted."

Just to clarify, you're saying if you make a selection that item is hilited
(as usual) but if you then make a second selection, both items are now
selected?

Have you double-checked that Multi-Select isn't set to Yes? Things set in the
Properties sheet have a way of not always staying set, apparently one of the
Access god's way of having fun..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top