Ignore On Current event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a command that will turn on/off events? Specifically I want to turn
off the On Current event until a search is complete.
 
In
ABM said:
Is there a command that will turn on/off events? Specifically I want
to turn off the On Current event until a search is complete.

The Current event will fire whenever a new record becomes current on the
form. You can't stop it. However, you can have your code choose
whether or not to respond to it. For example, you can set a
module-level variable when you start your search, and clear it when your
search is over. Then the code in the Current event procedure can check
that variable to decide whether or not to to do whatever it is that it
would normally do.

If you don't mind my asking, what kind of search are you doing, that is
going to cause the Current event to fire while it's going on?
 
I was thinking the same thing a Dirk.

If you are "searching" the current forms recordset for some value, you would
be far better off searching a recordsetclone. Then, when you find what you
are looking for, set the forms bookmark property equal to the clones bookmark
property.

As an example, if you have an unbound textbox (txt_FindSSN) in the forms
header, with a command button (cmd_FindSSN), the code behind the button might
look like:

Private Sub cmd_FindSSN

IF len(me.txt_FindSSN & "") <> 9 then Exit sub

Dim rs as dao.recordset
set rs = me.recordsetclone
rs.findFirst "[SSN] = '" & me.txt_FindSSN & "'"
if rs.nomatch then
msgbox "no match for this SSN"
else
me.bookmark = rs.bookmark
endif

rs.close
set rs = nothing
end sub

HTH
Dale
 
Back
Top