Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

Remember index place in userform listbox

I have a Useform(model) that contains a listbox.

I'm hiding the form and then reshowing the form modelessly.

When I do this I lose my place in the listbox index ?

Is there a way to go back to the same place in the listobx before I hide the userform ?

Thanks
fordraiders

Private Sub CommandButton8_Click()
'
Me.Hide
Me.Show vbModeless
'
With frmList
            .Height = 225
            .Top = Application.Top + 350  
            .Left = Application.Left + 25    
End With

End Sub

Open in new window

Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

I can't replicate that. Any code in the form's activate event?
Avatar of Fordraiders

ASKER

well, here is what I did.  Since hiding the form will kill
public variables...

I created textfile to hold the index number and write it to a FreeFile.

Then when the form is unhidden...tell the listbox to go to the listindex number from the freefile.

Public sidx as integer


sidx = Me.ListBox1.ListIndex


after re-opening the freefile



' ok we should have it and find correct index
ListBox1.SetFocus
With frmList
With ListBox1
  .Selected(sidx) = True
End With

End With
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry , I think its the refreshing of the listbox data ?
Nope that shouldn't do it either.
ok sorry its the error handling that deleting the variables.
I put in proper error control and now at least don't lose the variable

created a public variable  

i =  listbox1.listindex

and when the form unhides..just set the list box to the saved index holder.
Thanks