exiting from before update

tanzania

Registered User.
Local time
Yesterday, 16:13
Joined
Oct 20, 2006
Messages
91
Hi, I have the code below that checks the If condition and returns a msgbox if true. i want to exit the beforeupdate sub when the person clicks ok (ie go back to the form), but it keeps on going through the code even after cancel? Note that I can't rely soley on the required field condition due to other code I need witht he database.
any help appreciated!

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

Dim strMsg As String

Forms!Home_Oxygen_Form![Hospital No:].SetFocus
If Forms!Home_Oxygen_Form![Hospital No:] = " " Then
MsgBox "You must enter a Hospital Number", vbOKOnly
Cancel = True

Else

End If
...other code here
 
Hi, I have the code below that checks the If condition and returns a msgbox if true. i want to exit the beforeupdate sub when the person clicks ok (ie go back to the form), but it keeps on going through the code even after cancel? Note that I can't rely soley on the required field condition due to other code I need witht he database.
any help appreciated!

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

Dim strMsg As String

Forms!Home_Oxygen_Form![Hospital No:].SetFocus
If Forms!Home_Oxygen_Form![Hospital No:] = " " Then
MsgBox "You must enter a Hospital Number", vbOKOnly
Cancel = True

Else

End If
...other code here
 
Have a look at my attached sample.

If I may suggest something, I would not use Hospital No:, you could use Hospital No but leave off the :

I don't like spaces much either so I would have HospitalNumber.
 

Attachments

...
Cancel = True
Exit Sub
...
 
...but it keeps on going through the code even after cancel?
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate

    Dim strMsg As String
    
    Forms!Home_Oxygen_Form![Hospital No:].SetFocus
    If Forms!Home_Oxygen_Form![Hospital No:] = " " Then
        MsgBox "You must enter a Hospital Number", vbOKOnly
        Cancel = True
      [B][COLOR="Red"]Exit Sub[/COLOR][/B]
    Else
     
    End If
...other code here

The code doesn't stop at Cancel=True, so you have to make it stop if you don't want further code executed.
 
its ok ive worked it out and btw i had no control over double post as my comp was playing up yet again...unless u can tell me of a way to delete my own post....
 

Users who are viewing this thread

Back
Top Bottom