Userform 1 has a button which opens Userform2, which automatically displays in front of Userform1. Of course, both properties are set to Showmodal = True.
i want to be able to interact with Userform1 in the background, then return back to Userform2 which still remains on top of Userform1 and interact with it as well - i.e., back and forth.
I copied this code from the web and checked it to make sure it was copied correctly, and put it in the General Declarations at the top section of the Userform1(form in the background - behind Userform2).
It does not work. My question is, is there any additional code I may be leaving out or that's missing from Userform1 or Userform2
that will allow this to work correctly?
I know this has been done successfully.
Thanks in advance for anyone's help.
cr
i want to be able to interact with Userform1 in the background, then return back to Userform2 which still remains on top of Userform1 and interact with it as well - i.e., back and forth.
I copied this code from the web and checked it to make sure it was copied correctly, and put it in the General Declarations at the top section of the Userform1(form in the background - behind Userform2).
Code:
#If VBA7 Then
Dim mhwndForm As LongPtr 'The userform's window handle
Private Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#If Win64 Then
Private Declare PtrSafe Function SetWindowLongA Lib "user32" Alias "SetWindowLongPtrA" (ByVal Hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
Private Declare PtrSafe Function SetWindowLongA Lib "user32" (ByVal Hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
Private Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal Hwnd As LongPtr) As Long
#Else
Dim mhwndForm As Long 'The userform's window handle
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLongA Lib "user32" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal Hwnd As Long) As Long
#End If
Const GWL_HWNDPARENT As Long = -8
that will allow this to work correctly?
I know this has been done successfully.
Thanks in advance for anyone's help.
cr