2nd Form deselects list box items on main form

  • Thread starter Thread starter RandyDtg1
  • Start date Start date
R

RandyDtg1

I have a user form with a multi select list box. One of my functions selects
list items recommended for the user. I then put up a second form with the
selected count, but when the 2nd form is hide or unload, selected items on the
first form get unselected.

It works with a msgbox, but I would rather use the 2nd form because I use mouse
move to hide the form, and that I think is neat.

What causes the listbox items to loose their selected status?

Thanks.
 
show the code where you show the second form and the code where you hide the
second form and show the first form again.
 
First form is never unloaded or hidden
Note below, if I use the Msgbox, the boxes stay selected on the first form.

'Code in first form code module
Private Sub cmdFind_Click()
Response = InputBox("Enter text to find:", Title, FindText)
If Response = "" Then Exit Sub
FindText = Response: Cntr = Zero
For I = 0 To frmrwGetter.lstrGetter.ListCount - 1
temp = lstrGetter.List(I) ' gives Value
J = InStr(One, temp, "@", vbTextCompare)
If J > Zero Then temp = Left(temp, J - One)
J = InStr(One, temp, FindText, vbTextCompare)
If J > Zero Then
lstrGetter.Selected(I) = True
Cntr = Cntr + One
End If
Next I
' MsgBox Cntr & " found.", vbInformation, Title
Load frmFound
frmFound.lblFound.Caption = Cntr & " Found."
frmFound.Show
End Sub

'Code in second form code module
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer,
ByVal X As Single, ByVal Y As Single)
frmFound.Hide
End Sub
 
It worked OK for me. However, it is possible that the form doesn't get
updated, so put in a doevents and possibly a repaint

Private Sub cmdFind_Click()
Response = InputBox("Enter text to find:", Title, FindText)
If Response = "" Then Exit Sub
FindText = Response: Cntr = Zero
For I = 0 To frmrwGetter.lstrGetter.ListCount - 1
temp = lstrGetter.List(I) ' gives Value
J = InStr(One, temp, "@", vbTextCompare)
If J > Zero Then temp = Left(temp, J - One)
J = InStr(One, temp, FindText, vbTextCompare)
If J > Zero Then
lstrGetter.Selected(I) = True
Cntr = Cntr + One
End If
Next I
Me.Repaint '<== added line
DoEvents '<== added line
' MsgBox Cntr & " found.", vbInformation, Title
Load frmFound
frmFound.lblFound.Caption = Cntr & " Found."
frmFound.Show
End Sub
 

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

Back
Top