briansmithdanisco
IS-IT--Management
I have a main form with 2 sub-forms that have been added to two of the tab controls on the main form. All three have VB added in the OnOpen event. One of the sub-forms, called MiscResource, has a few triggered on-exit events for a few of the fields when data is entered.
The problem I have is when I open the main form and logic passes to each of the OnOpen modules for the main form and the 2 sub-forms, the flow of control continues to execute the other events in the MiscResource subform without the events taking place. An example is I have an On-Exit for a field that looks up a material description after the material number is entered. The On-Exit executes a function that does the query and fills in the display. After the OnOpen finishes, the program continues to go through the On-Exit logic, even though the form has not been displayed yet and nothing has been keyed in to trigger the On-Exit. After it finishes the On-Exit module, it continues to an AfterUpdate module I have in the same subform.
One thing I did find is that if I comment out the call to the material description function, the logic does not jump to the AfterUpdate module. Not sure why?
Why are the other modules being executed when the form is opened and not just the OnOpen part? I guess the way I think it should work is the OnOpen events finish, the form displays, and the logic stops until data is entered and the other triggered events take place.
If anyone can explain why everything seems to be executing when I think only the OnOpen event should run, it would be a big help.
Here is the OnOpen for the subform MiscResource:
Private Sub Form_Open(Cancel As Integer)
' If the close flag is Y then set the type to 2 (Snapshot - read only), else set to 0 (Dynaset)
If [Forms]![frmLiquidBatchSheet].Form![Closed] = -1 Then
Me.RecordsetType = 2
Else
Me.RecordsetType = 0
End If
End Sub
Here is the material lookup that keeps being executed after the OnOpen in the same subform MiscResource:
Private Sub MaterialNumber_Exit(Cancel As Integer)
' If the record is closed then skip all updates and changes.
If [Forms]![frmLiquidBatchSheet].Form![Closed] = -1 Then
Exit Sub
End If
' Lookup material description.
If Not Me.MaterialNumber Then
Me.MaterialName = LookupMaterialName(Me.MaterialNumber.Value)
End If
End Sub
Thanks.
The problem I have is when I open the main form and logic passes to each of the OnOpen modules for the main form and the 2 sub-forms, the flow of control continues to execute the other events in the MiscResource subform without the events taking place. An example is I have an On-Exit for a field that looks up a material description after the material number is entered. The On-Exit executes a function that does the query and fills in the display. After the OnOpen finishes, the program continues to go through the On-Exit logic, even though the form has not been displayed yet and nothing has been keyed in to trigger the On-Exit. After it finishes the On-Exit module, it continues to an AfterUpdate module I have in the same subform.
One thing I did find is that if I comment out the call to the material description function, the logic does not jump to the AfterUpdate module. Not sure why?
Why are the other modules being executed when the form is opened and not just the OnOpen part? I guess the way I think it should work is the OnOpen events finish, the form displays, and the logic stops until data is entered and the other triggered events take place.
If anyone can explain why everything seems to be executing when I think only the OnOpen event should run, it would be a big help.
Here is the OnOpen for the subform MiscResource:
Private Sub Form_Open(Cancel As Integer)
' If the close flag is Y then set the type to 2 (Snapshot - read only), else set to 0 (Dynaset)
If [Forms]![frmLiquidBatchSheet].Form![Closed] = -1 Then
Me.RecordsetType = 2
Else
Me.RecordsetType = 0
End If
End Sub
Here is the material lookup that keeps being executed after the OnOpen in the same subform MiscResource:
Private Sub MaterialNumber_Exit(Cancel As Integer)
' If the record is closed then skip all updates and changes.
If [Forms]![frmLiquidBatchSheet].Form![Closed] = -1 Then
Exit Sub
End If
' Lookup material description.
If Not Me.MaterialNumber Then
Me.MaterialName = LookupMaterialName(Me.MaterialNumber.Value)
End If
End Sub
Thanks.