Close from and open a new form on exit event?

  • Thread starter Thread starter Simon Webb
  • Start date Start date
S

Simon Webb

I have a form where the operator enters some text in a box. After they have
entered the text - a security code - on tabbing out I want to

i) close the current form.
ii) open another form.

conditional on the operator having entered the correct security code. If I
use the on exit event for my text box I get the error message 2585 "This
action cannot be carried out while processing a form event".

I think the only event is the exit event (the form is not bound. I have no
other events or code in this form). Is there any way around this?

I can have the cursor move to a command button which the operator can click
which will achieve what I want to do - but that is an extra step by the
operator.

thanks in advance

- Simon
 
Hi Simon

Not really what the problems as don't really have enough info about your form.

But I think you may be trying to use he close action on a field that has the
focus. You can always create an unbound field and set the focus to that
before the close and open action (hope that makes sense). This will mean
that your user still only has one button to press and that code will set the
focus - close - open - etc.

Try some thing like this "after" your passwork section

Private Sub ButtonName_Click()
Me.SomeHiddenField.SetFocus
DoCmd.Close acForm, "FormName"
DoCmd.OpenForm "FormName", acNormal, "", "", , acNormal
End Sub
 
Close your first form in the Open event of the form you open.
In case you need to be able to open the second form from other places, you
can check to see if it is loaded before you close it:

If CurrentProject.AllForms("FirstForm").IsLoaded Then
Docmd.Close acForm, "FirstForm"
End If
 
Back
Top