"Activate" when Passing Focus from a Form

grinnZ

Registered User.
Local time
Today, 03:47
Joined
Jun 29, 2011
Messages
38
I have a form that does multi duty. When the user inputs to a combo box and the item is not in the list the NotInList fires and opens an entry form for the new item. While passing to the new item entry form I also reconfigure my current form with the anticipation of a successful new item entry. Oh but then the user presses Cancel in the new item entry form and i have a reconfigured form that I need to change back. The new item form in its Cancel button click passes to the main form a True value to a hidden textbox called NewItemFail on the main form. My question is what event fires on the main form when the focus is passed back to it from the new item entry that is closing so that I can test this NewItemFail textbox and take the necessary action? I have tried OnGotFocus which didn't work even though the entry form's cancel implicitly sets focus back to the main form and now read that the OnActivate event does not fire between forms. So what does fire? Or must I do all my main form reconfiguration from the item entry cancel event? (Bleh, all of my config routines are private within the main form code.)

Code:
Private Sub cmdCancel_Click()

    With Me
        If .txtCallingForm = "frmItemCrafted" Then
            Forms(.txtCallingForm).txtNewItemFail = 1
        End If
        
        Forms(.txtCallingForm).SetFocus
        DoCmd.Close acForm, .Name
    End With
    
End Sub
 
Huh? A Form's OnGotFocus does not fire, if the form contains any controls capable of receiving focus. OnActivate should though - did you try?
 
Clicking cmdCancel in the item entry form runs the routine above and that's it. At this point I have the same routine waiting in the main form's OnGotFocus and OnActivate events. Neither fire. Below is how I open the new item entry form from the main.


Code:
Private Sub cboItem_NotInList(NewData As String, Response As Integer)

    If conErrorTrappingOn = True Then On Error GoTo Err_cboItem_NotInList
        
    Response = acDataErrContinue
    
    'CONFIG CONTROLS FOR NEW CRAFT ITEM ENTRY
' / ===============================
    Call NewCraftEntryOn
    Call ClearGrid
        
    'OPEN / SETUP ITEM ENTRY FORM
' / ===============================
    Call OpenItemEntry(NewData, Me.Name)
    
    
Exit_cboItem_NotInList:
    Exit Sub
    
Err_cboItem_NotInList:
    Call LogError(Err.Number, Err.Description, Me.Name & ", Private Sub cboItem_NotInList")
    Resume Exit_cboItem_NotInList

End Sub



Public Sub OpenItemEntry(NewData As String, FormName As String)

' / ===============================
    'called by frmInStockMSVAdjustments cboItem_NotInList
    'called by frmInvAdjustments        cboItem_NotInList
    'called by frmListItem              cboItem_NotInList
    'called by frmItemCrafted           cboItem_NotInList
' / ===============================

    DoCmd.OpenForm "frmItemEntry"
    
    With Forms!frmItemEntry
        !txtCallingForm = FormName
        !cmdAddEdit.Caption = "A&DD ITEM"
        !txtItem = StrConv(NewData, vbProperCase)
        !txtInStock = 1
        !txtLevel.SetFocus
    End With

End Sub
 
The docs say you are right - the OnActivate doesn't fire by itself. But how about just setting focus to some control on the form when closing your auxilliary form? That should trigger the OnActivate, as I read things.
 
Nope. I added this line after the original set focus and still nothing.

Code:
        Forms(.txtCallingForm).SetFocus
        Forms(.txtCallingForm).cboItem.SetFocus
        DoCmd.Close acForm, .Name

But I do have idea.

Considering that NewItemFail is an unbound textbox the value sent there will have to be sent to a temp table. From the cancel routine store the two values that the user would have input in variables, close the main and reopen, and in the Load event have it check the temp table for a fail value and proceed accordingly. Once loaded then simply repopulate the main form's values just before the entry cancel routine ends. It's a long way to the backdoor but it will probably work.
 

Users who are viewing this thread

Back
Top Bottom