I think I understand what you're trying to do, Sara. You're trying to automatically execute code on the MDI parent when the user closes the MDI child. But, the MDI parent doesn't expose any native events that allow this, as vladk points out.
I also believe I see where you're running into trouble. Once the user inputs a password and hits ok, you want to unload the form and start executing code in the parent form, and nothing happens.
Well, this is because you're trying to use an MDI form for a purpose it wasn't intended for. MDI forms are intended to work as discrete units, but related visually and logically by existing in a single container. The container is responsible for containing the children, and that's pretty much it. It's the children that are intended to do the work.
What you really need is to show the form modally, and an MDI child form can't be because it's against its nature. You want to show a form, get a result from that form, and move on based on that result. Personally, I wouldn't use an MDI form, rather I would use a regular form set up as a dialog box. (Set the style property to fixed dialog.)
Here's some code from a project. doLogin shows a login dialog and returns false if not successful, true if successful. If true, it sets some global variables with information from the login. I set this up as a separate proc here because I'm working with multiple forms based on the screen size of the client. You might not need to make a separate proc, but could just put similar code in form_load for your main form.
Code:
Private Function doLogin(lCn As ADODB.Connection) As Boolean
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
doLogin = False
With frmLogin
Set .lCn = lCn
.Show vbModal
Select Case .LoginStatus
Case my3Strikes
MsgBox "Third login failure; exiting program"
Case myCancel
MsgBox "Login canceled; exiting program"
Case mySuccess
DealerCode = .DealerCode
DealerName = .DealerName
doLogin = True
End Select
End With
Unload frmLogin
End Function
frmLogin has 2 text boxes: Dealer code (user code, as it were) and password, as well as an Ok and a Cancel button. Here's the code in frmLogin:
Code:
Option Explicit
Enum LogVals
my3Strikes = 0
myCancel = 1
mySuccess = 2
End Enum
Public LoginStatus As LogVals
Public DealerCode As Long
Public DealerName As String
Public lCn As ADODB.Connection
Private Sub cmdCancel_Click()
LoginStatus = myCancel
Me.Hide
End Sub
Private Sub cmdOK_Click()
'check for correct password
Static TryCount As Integer
Dim rs As ADODB.Recordset
If txtDealerCode.Text = "" Then
MsgBox "Enter a dealer code"
txtDealerCode.SetFocus
Exit Sub
ElseIf txtPassword.Text = "" Then
MsgBox "Enter a password"
txtPassword.SetFocus
Exit Sub
End If
TryCount = TryCount + 1
Set rs = New ADODB.Recordset
With rs
.Open "select dlr_code, dlr_pword, dlr_name from dealeraccounts where dlr_code = '" & txtDealerCode.Text & "'", lCn
If .EOF And .BOF Then
If TryCount = 3 Then
LoginStatus = my3Strikes
Me.Hide
Else
MsgBox "Invalid Password for Dealer Code " & txtDealerCode.Text, , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
.Close
End If
ElseIf txtPassword.Text = !dlr_pword Then
LoginStatus = mySuccess
DealerCode = !dlr_code
DealerName = !dlr_name
Me.Hide
ElseIf txtPassword.Text <> !dlr_pword Then
MsgBox "Invalid Password for Dealer Code " & txtDealerCode.Text, , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
.Close
ElseIf TryCount = 3 Then
LoginStatus = my3Strikes
Me.Hide
End If
End With
End Sub
Notice that I didn't bother with property procedures in this case, since I didn't need any functionality that public variables don't provide. Or, maybe it's because I'm lazy.
Anyway, hope this helps.
Bob