dastrw
asked on
Bring Form to Front
I have a form that is launched from another form. The first thing it does when it comes up is bring up a file browser so that the user can select an Excel workbook. The user is then supposed to work with the launched form to interact with the Excel workbook. However, in most cases the Excel workbook completely covers the launched form. So the user never sees it to know that there is anything to do.
Is there a way to bring the launched form back on top of the Excel workbook? I don't want my launched form to become a topmost form that always stays on top. I just want it to pop to the front.
Is there a way to bring the launched form back on top of the Excel workbook? I don't want my launched form to become a topmost form that always stays on top. I just want it to pop to the front.
Use the form load event in VBA to load form on top.
ASKER
Could you give me some sample code?
You must use the "SetWindowPos API"
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_ONTOP = -1
Private Const flags = SWP_NOMOVE Or SWP_NOSIZE
SetWindowPos frm1.hwnd, HWND_ONTOP, 0&, 0&, 0&, 0&, flags
So when you call the form (frm1) then, you call the "SetWindowPos API" and the form will allways be on top
FerG
Saludos
--
Ing. Fernando D. Giletta
San Fco. Cba. Argentina.
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_ONTOP = -1
Private Const flags = SWP_NOMOVE Or SWP_NOSIZE
SetWindowPos frm1.hwnd, HWND_ONTOP, 0&, 0&, 0&, 0&, flags
So when you call the form (frm1) then, you call the "SetWindowPos API" and the form will allways be on top
FerG
Saludos
--
Ing. Fernando D. Giletta
San Fco. Cba. Argentina.
ASKER
I already saw that comment. I don't want the window to always be on top. That will be annoying for the user. I just want the form to come to the front.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is exactly what I needed.
;-)
ASKER
There is just a minor problem with the AppActivate method: If I manually bring up the launched form then just it shows up in front of my Excel workbook. If I use the AppActivate command then the entire Access application comes up in front of the Excel workbook. It would be nice if I could get AppActivate to just show the launched form, but the launched form doesn't have its own individual menu name as far as Windows is concerned. This is just nit-picking though.
Yeah,
This is probably about as simple as it gets without using complicated API Code.
Jeff
This is probably about as simple as it gets without using complicated API Code.
Jeff