
Originally Posted by
Logophobic
Touche, and modified accordingly.
Although it doesn't really make a difference, if you access a self-defined Public-Property of
a certain Form-Class - or a selfdefined TextBox on that same Form-Class - both require
that you use a concrete Form-Interface...
That said, when working with small Dialogue-Forms which often are shown only modally,
and have to return something to the caller - one can avoid using Hide or QueryUnload
and whatnot in the modal-form by simply defining a Public Function on it, which
internally also ensures the modal showing:
e.g. into Form2 (the one which is shown modally - having the usual Cancel and an OK-Buttons):
Code:
Option Explicit
Private mCaption As String
Public Function ShowModalAndGetNewCaption(OwnerForm As Object, CurCaption As String) As String
mCaption = CurCaption
Show vbModal, OwnerForm
ShowModalAndGetNewCaption = mCaption
End Function
Private Sub cmdOk_Click()
mCaption = txtNewCaption.Text
Unload Me
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
And within the Calling Form an explicit instantiation (combined with a single method call) is possible:
Code:
Option Explicit
Private Sub cmdArr_Click(Index As Integer)
With New Form2
cmdArr(Index).Caption = .ShowModalAndGetNewCaption(Me, cmdArr(Index).Caption)
End With
End Sub
The With construct above ensures, that an entire new Form2-instance is created -
and after the call (after running over End With) again absolutely destroyed.
Olaf