Avatar of Fordraiders
Fordraiders
Flag 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

Microsoft Excel

Avatar of undefined
Last Comment
Fordraiders

8/22/2022 - Mon
Rory Archibald

I can't replicate that. Any code in the form's activate event?
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
Rory Archibald

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Fordraiders

ASKER
Sorry , I think its the refreshing of the listbox data ?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Rory Archibald

Nope that shouldn't do it either.
Fordraiders

ASKER
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.
Fordraiders

ASKER
Thanks
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.