Need to know when subform OnCurrent event fires by itself (1 Viewer)

Kronix

Registered User.
Local time
Today, 15:11
Joined
Nov 2, 2017
Messages
102
I have a main form for orders and a subform for items in the order. As I understand it, the subform OnCurrent event fires both when I move through the subform and when I move through the main form to a different order.

As we know, subform Load and onCurrent events fire before main form events, causing subform events to fire multiple times in response to actions in the main form events. I want to prevent the subform from loading multiple times each time the main form record is changed, by checking a global boolean variable in the main form and only firing the subform's OnCurrent event when the boolean signifies the main form has loaded with a True value.

The problem is, after the main form has loaded the first time, I see no way to prevent the subform from firing multiple times when the main form record is changed. I need some way to set the boolean variable to false when the main form record is changed, but before the subform onCurrent event fires. Then at the end of the main form's OnCurrent Event the boolean will be set to True again.

Since the subform OnCurrent event will always fire first, I need some way to know that it is being fired as a result of the main form record being changed. How am I supposed to get this information? Does anything fire or change before the subform's OnCurrent event when the main form's record is changed?
 

Ranman256

Well-known member
Local time
Today, 09:11
Joined
Apr 9, 2015
Messages
4,337
onCurrent fires when you change records.
if its a main form oncurrent event, then it is NOT affected when you change records
in its subform. nothing should fire.

if Oncurrent is in the subform, then will fires everytime the subform rec moves
or whenthe master form changes record too.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:11
Joined
May 7, 2009
Messages
19,242
if you don't want your subform current event fires, while on the main form, dont set any Link Parent/Child link to the subform.
set the subforms recordsource on the current event of the main form. and only when you change record.

on parent form:

Private Sub Form Current()
'lngID is the AutoIncrement field
Static lngID As Long
If Me.NewRecord Then
lngID = 0
Me.SubformName.Form.RecordSource = "Select * From subformTable Where ID=" & lngID
Else
If lngID <> Me.AutoIncrementFieldName Then
' save it
lngID = Me.AutoIncrementFieldName
' set the subforms recordsource
Me.SubformName.Form.RecordSource = "Select * From subformTable Where ID=" & lngID
End If
End If
End Sub
 
Last edited:

Users who are viewing this thread

Top Bottom