|
-
November 8th, 2010, 11:14 AM
#1
[RESOLVED] Retrieve Modal Ownerform Name
I am hoping this is a simple question but I have been struggling to find any details for this.
I have a form that is being shown modal from a number of other forms within my application. Each form opens the form thus...
Code:
frmStockList.Show vbmodal, me
According to Microsoft the second parameter is 'OwnerForm'. How can I retrieve the name or any other property of OwnerForm from within frmStockList ?
Any help on this would be greatly appreciated.
-
November 8th, 2010, 02:11 PM
#2
Re: Retrieve Modal Ownerform Name
I am quite sure that there has to be an easier way to do this, but what I'd do is to create a global form variable object, and just before you call the modal form set it to the form calling the modal form. Then in the modal form, you can reference the names/properties of anything in that form. Like so:
Code:
' In your module for global variables
public frmFormObject as form
.
.
.
' In any form that makes the call to the modal form
set frmFormObject as new form
frmFormObject = me
.
.
.
' In the modal form
frmFormObject.Text1.Text= [insert whatever you need to do]
It's crude, and needs to be tested to make sure that the syntax is correct, but this should work.
-
November 9th, 2010, 07:41 AM
#3
Re: Retrieve Modal Ownerform Name
Try this in the modal form;
Private mCallingForm As Form
Public Sub OpenModal(Owner As Form)
Set mCallingForm = Owner
Show vbModal, Owner
End Sub
Private Sub Form_Activate()
Print "Owner = " & mCallingForm.Name
End Sub
and this in the owner;
Private Sub Command1_Click()
Form2.OpenModal Me
End Sub
-
November 10th, 2010, 01:19 PM
#4
Re: Retrieve Modal Ownerform Name
Hi,
Thanks for the help, I finally found a solution to this. I still don't know why there isn't an OwnerForm Property but anyway....
In your module Declarations.
Code:
Public Declare Function GetWindow Lib "USER32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Global Const GW_OWNER = 4
In your module code.
Code:
Public Function GetOwnerFormName(frm As Form) As String
Dim WindHand As Long
Dim ctr As Integer
GetOwnerFormName = ""
WindHand = GetWindow(frm.hWnd, GW_OWNER)
For ctr = 0 To Forms.Count - 1
If Forms(ctr).hWnd = WindHand Then
GetOwnerFormName = Forms(ctr).Name
Exit For
End If
Next
End Function
And finally to call function.
Code:
OwnerFrm = GetOwnerFormName(Me)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|