tags:

views:

80

answers:

3

I have an event procedure which is to be run when user select 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 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

A: 

You've pretty well answered your own question - why don't you use the ON LOAD event?

dsteele
but when i move the cursor to another record, the event procedure needs to be called. with on load, it won't be called
Sorry, you're right. I read your question and assumed you were showing one row at a time and reloading the form for each row selection. Simon's solution is better.
dsteele
+2  A: 

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...

Simon
+1  A: 

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.

Renaud Bompuis
i think this is what simon's solution is.. then add Form_Close or form_deactive isloading = true?
No need to add anything when the form is closing. Once it is closed the object is normally destroyed. If you re-open it again, new form object will be created with all the values initialised. Variables that belong to a form die with it.
Renaud Bompuis