Solved

2 userforms modeless taking focus back to another in a certain object

Posted on 2013-01-31
8
339 Views
Last Modified: 2013-02-01
excel 2010 vba

I have 2 userforms  both modeless.
Userform1
Userform2

I open useform1
Then userform2
 
and once I'm done with userform2
I want to move the focus back to userform1


Problem.  I have Multipage object on Userform1. ( 8 tabs  )

First I need to make sure when I move back to the Useform1 I go to the right place.

So
if on Useform1 ,  Multipage (2) was the current tab,   I want to go to listbox2
that has a currently selected Item ?




Thanks
fordraiders
0
Comment
Question by:fordraiders
  • 4
  • 4
8 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 38841722
In userform2 Terminate event put code that selects userform1.multipage(2) or userform1.ListBox2.Setfocus
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 38842031
You may have to do

userform1.show
userform1.ListBox2.Setfocus
0
 
LVL 3

Author Comment

by:fordraiders
ID: 38842226
ok..that sounds simple enough..

But,  would i not have to loop through the listbox and see which one has the item selected to back to that item ?

i.e. If i had 20 items in the listbox and 17 was selected..i need to go back to that line in the listbox...

Thanks
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 38842255
Listbox1.Listindex will tell you which one is selected, if you just need to know the value you can do Listbox1.Text
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Closing Comment

by:fordraiders
ID: 38842272
Thanks
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 38842309
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 - 2012
0
 
LVL 3

Author Comment

by:fordraiders
ID: 38844003
Martinliss,

these are the actual values Im using:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
frmResultAll.MultiPage1.SetFocus
frmResultAll.MultiPage1.Value = 0
frmResultAll.ListBox1.SetFocus
Unload UserForm1
end sub


The focus is still on the sheet1...

The userform
frmResultAll  does not get the focus..?
0
 
LVL 3

Author Comment

by:fordraiders
ID: 38844045
ok for some reason got this to work...sorry to bother you...

The form is already showing...but

I forgot your first line of code..!



frmResultAll.Show
frmResultAll.MultiPage1.SetFocus
frmResultAll.ListBox1.SetFocus
Unload UserForm1
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now