Active user form

G

gregork

Hi,
On a user form (1) I have a combo box click event that activates another
user form (2) to show (vb modeless) . I have both userforms showing
simultaneously in different positions on the sheet. The first user form is a
product entry form and the second user form displays specifications relating
to the product selected in the combo box on user form 1.
The first problem I have is that I want the focus to remain on user form1
(text box2 to be specific). I am not sure how to have the second user form
show without the focus leaving the first form. Is this possible?
The second problem is that if I make another selection on the combo box
(ufrm1) while both forms are shown (modeless) I then have to close and then
re-open user form 2 in order to update the values on the form. I should
explain ufrm 1 combo box click writes a value to my worksheet and ufrm 2
looks up the value on another sheet and displays the relative data.
I know it would be a simple solution to have everything on the same userform
but this is not feasible with the layout of my sheet and it would great if
someone could help me find a way around this.

Regards
gregork
 
C

Chip Pearson

To keep Userform1 active after displaying Userform2, use code
like the following:

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal HWnd As Long) As Long

Private Sub CommandButton1_Click()
Dim HWnd As Long
HWnd = FindWindow("ThunderDFrame", Me.Caption)
UserForm2.Show vbModeless
If HWnd Then
SetForegroundWindow HWnd
End If
End Sub

For your second question, create a public procedure in Userform2
that will update the controls, and call the procedure from a
control in Userform1.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
G

gregork

Hi Chip,
Many thanks Chip the code works brilliantly well. I really didn't think
there was a way to do that.

Kind Regards
gregork
 

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