Cancel OnExit event when another Command button is pressed

rede96

Registered User.
Local time
Today, 15:23
Joined
Apr 2, 2004
Messages
134
Hi,

I have a form with a control for the user to enter some data and then two command buttons 'OK' and 'Cancel'

For the OnExit event in the control I have a procedure that check the user input and if incorrect, opens a message box with an error message asking the user to correct the data. It then cancels the event so the focus remains in the current control.

However if the user presses the 'Cancel' command button on the form to cancel & close the form, the OnExit event for the current control still fires and askes the user to correct the data.

In my code in the control, how can I recognise that the Cancel command button has been pressed, so I can cancel the OnExit event and close the form?

THanks!
 
DONT put it in OnExit,
on the OK click event run a Validation routine to check your entries....then exit.
if IsValidForm() then docmd.close

Code:
public Function IsValidForm() as boolean
dim vMsg

  select case true
       case txtName = "" 
          vMsg = "Client Name is missing"

       case isnull(cboState )
          vMsg = "State is missing"
      cboState.setfocus

  end select
  if vMsg <>"" then msgbox vmsg,vbCritical,"Required"
  IsValidForm =vMsg =""
end sub
 
DONT put it in OnExit,
on the OK click event run a Validation routine to check your entries....then exit.

Thanks, that is probably the right thing to do. I did already do it that way originally but wanted to get the user to correct any errors before they moved to the next control. I just thought it would be cleaner to correct errors as you go along instead of getting a list when you press 'OK' (As there are several control box to fill in data.)

But that did give me an idea. I could move the check to the after update event. It won't stop the user from being able to move to another control but I could pass a flag to the next control using the OnEnter event, which would tell it to move back to the previous control on an error.

That way when the user clicks cancel it won't matter. I'd still need to put a check in the 'OK' control too of course.

Anyway, I will try that. Thanks.
 

Users who are viewing this thread

Back
Top Bottom