Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

quick focus help needed

Status
Not open for further replies.

mettodog

Vendor
Jul 11, 2000
94
US
Is there a way to find out what form was last in focus? Not the form that is currently in focus, but the one that was in focus before it?
 
Yes

The previous form's LostFocus event will fire...if you're shifting focus.

In the Lostfocus event you can maybe set a global flag determining the last form that had the focus. The form receiving the focus, queries that flag & sets it to itself since it now has focus.

Have fun
caf

 
can you show me some code? this is what i have as far as form layout.(MDI) there is a rtf form. you click properties, another form pops up and gaines focus, it needs to know what the name of the form that last had the focus is.
 
(outside of any sub....)
Option Explicit
Global gblLastFormName As String
Global gblCurrentFormName As String




In your form_load events.....trap the form name
Sub Form_Load

gblLastFormName = gblCurrentFormName

gblCurrentFormName = Form.Name
End Sub


This way you have a "rolling" value of present and last form names.

This should get you started.

John

 
whenever i do gblLastFormName.color = green or anything like that, it gives an error, something about it being an invalid container or something like that.
 
I think I know what you after. Put this code in a module.


Public Function CallingForm(ByVal hWnd As Long) As Form
'Return the Form that launched the given Window
Dim lHwnd As Long
Dim oForm As Form

'get the Handle of the Window that Loaded this Window
lHwnd = GetNextWindow(hWnd, GW_HWNDNEXT)
'Find a match in the "Forms" collection
'and return a reference to it
For Each oForm In Forms
If oForm.hWnd = lHwnd Then
Set CallingForm = oForm
Exit For
End If
Next
End Function



And then you will reference (lets say a text box on that form) this previous active form like this

Callingform(hwnd).text1.text = "NEW TEXT"

David Paulson


 
YES! thats exactly what i needed, but one question, the form that i want to call the text(rtf) box form is a new version of another form, do you understand what i mean? Dim MyForm as New ThisIsMyForm. So will it work then? Because every new *file-new* form that i create, is named MyForm. So will this still work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top