rtochip
rtochip

Reputation:

How to check if CURRENT event is not during the OPEN event of form

I have an event procedure which is to be run when user selects a certain record.

If I put it in an ON CURRENT event, it works.

However, I don't need it to run when the form is being opened. That is, when the form is opened and the records are loaded onto the form, my event procedure is called up for every record that is loaded. It slows my program down as this is unnecessary.

My question is, how do I check that the event is not run during the "loading" of the records.

something like:

on_current_event do:

if event is not during on_load then
do this
end if

end proc

Upvotes: 3

Views: 2478

Answers (2)

Renaud Bompuis
Renaud Bompuis

Reputation: 16776

In your form's code:

Private isLoading As Boolean

Private Sub Form_Open(Cancel as Boolean)
    isLoading = True
End Sub

Private Sub Form_Current()
    If isLoading Then 
        isLoading = False
        Exit Sub
    End If
End Sub

That way the first occurence of the OnCurrent event when the form is opening will be bypassed.

That being said, it looks to me that this is not your real underlying problem but you will need to give more information (open another question) if you want other people to try to help.

Upvotes: 3

Simon
Simon

Reputation: 6152

Why not declare a form level boolean variable and set it to true when the form has finished loading?

In your OnCurrent event you can then do something like:

If Variable then
  Do Stuff
Else
  Don't do stuff
End If

This is probably not addressing the underlying issue however...

Upvotes: 3

Related Questions