Sending keyboard default/cancel events to parent form from subform (1 Viewer)

mdlueck

Sr. Application Developer
Local time
Yesterday, 20:30
Joined
Jun 23, 2011
Messages
2,631
Dealing with the complexities of the subform environment...

I need to somehow send the cancel event to the parent form, but I believe I must still set the default / cancel events within the subform context.

I am trying to send (forward) the event to the parent form and am getting an error attempting to do so. Code on the subform is as follows:

Code:
Private Sub btnClose_Click()
  On Error GoTo Err_btnClose_Click

  'Hack to flush keystrokes out of the buffer so that close via Esc does not generate an error msg
  DoEvents

  'Close window "parent"
  [COLOR=Red]Call Me.Parent.Form.Close_Click[/COLOR]

Exit_btnClose_Click:
  Exit Sub

Err_btnClose_Click:
  Call errorhandler_MsgBox("Form: Form_subform_metooling_gaging, Subroutine: btnClose_Click()")
  Resume Exit_btnClose_Click

End Sub
And the error I get on the red LOC is as follows:

Code:
Date: 20120118 Time: 14:49:05 UserID: c_mlueck
AppErrorMsg: Form: Form_subform_metooling_gaging, Subroutine: btnClose_Click()
Error Source: Fandango_FE
Error Number: 2465
Error Description: Application-defined or object-defined error
MessageText: The server has reached the maximum number of connections it supports.
Yes, the parent form has the Close_Click event.
 

thechazm

VBA, VB.net, C#, Java
Local time
Yesterday, 20:30
Joined
Mar 7, 2011
Messages
515
I guess I am a little confused. Do you have two close buttons? One on the parent and one on the sub and if so why?
 

mdlueck

Sr. Application Developer
Local time
Yesterday, 20:30
Joined
Jun 23, 2011
Messages
2,631
Do you have two close buttons?

Ja

One on the parent and one on the sub and if so why?

Setting the default / cancel buttons needs to go to a button control. I would assume on the same form (Me).

So I was thinking to hide the button on the subform, turn off the tab stop, etc.. just use a button to meet the requirement of "setting a default / cancel control". Otherwise buttons on the main form are the ones that are visible and to be used.
 

mdlueck

Sr. Application Developer
Local time
Yesterday, 20:30
Joined
Jun 23, 2011
Messages
2,631
I would assume on the same form (Me).

Ei, this works...

Code:
  'Sets Command_Close as the button control that is clicked when the user presses the ESC key.
  Me.Parent.btnClose.Cancel = True
Problem solved. One may reference parent form controls and assign them events from subforms! Woo hoo! :D
 

Users who are viewing this thread

Top Bottom