Question You are subscribed to this thread subforms GotFocus ev

C

Cyberwolf

I have a form that has a subform that contains a subform. On this 2nd subform
I have a control that has a GotFocus event. When I open the main form the
GotFocus event fires. Here is the code on the GotFocus event.


Private Sub ReasonID_GotFocus()
Dim intResp As Integer
On Error GoTo ReasonID_GotFocus_Error

stLinkCriteria = "[ReasonCodeID]=" & Me.ReasonCodeID
If Me.ReasonID = 1 Then
intResp = MsgBox("Would you like to view the RPP Cause records?",
vbYesNoCancel, "Releated RPP Cause Records available!")

If intResp = vbYes Then
DoCmd.OpenForm "frm_RPPCauseInfo", acNormal, , stLinkCriteria,
acFormReadOnly, acDialog
End If
End If

On Error GoTo 0
Exit Sub

ReasonID_GotFocus_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
ReasonID_GotFocus of VBA Document Form_frm_ReasonCodes_subform"
End Sub
 
J

John W. Vinson

I have a form that has a subform that contains a subform. On this 2nd subform
I have a control that has a GotFocus event. When I open the main form the
GotFocus event fires. Here is the code on the GotFocus event.

You've made a statement. As best as I can tell you have not asked a question.

Do you not want the event to fire? Do you want something else to happen when
it does?
 
L

Linq Adams via AccessMonster.com

Maybe I missed it; where's the question? Maybe that you don't want this to
happen, and how to prevent it?

When a form/subform (or in this case, a form/subform/subform) opens the
subforms actually open first, which is to say the Form_Open and Form_Load
events for the subforms fire before those of the main form.

If, when the 2nd subform open the ReasonID field has a GotFocus event and it
has the focus when that form first opens, the GotFocus event is going to fire.


As a workaround , in the Form_Load event for the 2nd subform, set the focus
to any field except ReasonID

Private Sub Form_Load()
Me.AnyFieldExceptReasonID.SetFocus
End Sub
 
C

Cyberwolf

Sorry,

Actually I figured this out. My questions was supposed to be, why is the
gotfocus event firing on the subform when the main form opens. I did some
more research and found that the gotfocus event fires when on a subform when
the form is opened because it loads all of the records for the main forms
record.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top