By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,806 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,806 IT Pros & Developers. It's quick & easy.

Using Nulls on Beforeupdate of form and Exiting w/o errors

Researcher
P: 2
Hello,

I have successfully validated my form fields thru the use of Isnull statements in the beforeupdate event of a form, works great. However when I attempt to exit the form, my first field has the focus due to a tab stop 0. When leaving the form the field message appears "must complete this field prior to exiting form.
How can I disable the isnull check when exiting? I tried changing the focus but did not work. Any ideas would be appreciated...

Thank You,

Researcher
Aug 27 '08 #1
Share this Question
Share on Google+
4 Replies


missinglinq
Expert 2.5K+
P: 3,532
Validation data insuring that a field is populated is supposed to execute if the user tries to exit the form when the field on the current record is empty. Are you saying that the field in questioned has data but the message is appearing anyway?

You need to post your Form_BeforeUpdate sub so that we can look at it.

BTW, the first field having focus when you exit the form is not because it has a Tab Stop of 0, that's just coincidental.

Welcome to Bytes!

Linq ;0)>
Aug 27 '08 #2

Researcher
P: 2
No, Let me explain further. After data is entered into the form and the record has been saved to table, the form clears and awaits a new record entry, however when attempting to exit the form thru an exit button, the validation check occurs because of no data in the field or fields. I can still exit the form, but without viewing those validation error messages. How can I exit the field w/o viewing the messages and still have field/form validation w/o null entries?

I realize the tab index number is only valid if you have a tab stop, setting the focus to that respective field controls the first field assigned.

Here is the code in the beforeUpdate event of the form:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_BeforeUpdate(Cancel As Integer)
  3.  
  4.    If IsNull(Me.Events) Or Me.Events = "" Then
  5.         MsgBox "You must Select an Event for this field ", vbCritical
  6.         Cancel = True
  7.         Me.Events.SetFocus
  8.       Exit Sub
  9.    End If
  10.  
  11.    If IsNull(Me.NoofCalls) Or Me.NoofCalls = "" Then
  12.         MsgBox "You must enter the number of calls for this event, if no event enter zero, the field cannot be blank", vbCritical
  13.         Cancel = True
  14.         Me.NoofCalls.SetFocus
  15.       Exit Sub
  16.    End If
  17.  
  18.    If IsNull(Me.BoxOfficeCalls) Or Me.BoxOfficeCalls = "" Then
  19.         MsgBox "You must enter the Box Office Calls, if no event, enter a number greater then zero, otherwise enter a zero, the field cannot be blank", vbCritical
  20.         Cancel = True
  21.         Me.BoxOfficeCalls.SetFocus
  22.       Exit Sub
  23.    End If
  24.  
  25.    If IsNull(Me.Operator) Or Me.Operator = "" Then
  26.         MsgBox "You must enter an operator name, the field cannot be blank", vbCritical
  27.         Cancel = True
  28.         Me.Operator.SetFocus
  29.       Exit Sub
  30.    End If
  31.  
  32.    If IsNull(Me.Shift) Or Me.Shift = "" Then
  33.         MsgBox "You must enter the operator's shift, the field cannot be blank", vbCritical
  34.         Cancel = True
  35.         Me.Shift.SetFocus
  36.       Exit Sub
  37.    End If
  38. End Sub
Aug 27 '08 #3

NeoPa
Expert Mod 15k+
P: 31,489
The point here is that if you close the form with pending amendments to the data, then it saves those changes away for you. Not good to lose the validation for the convenience of exiting quickly.

I would consider using Me.Undo in your Exiting code before trying to exit. That way it assumes any changes should be aborted rather than saved.

Does this make sense?
Aug 30 '08 #4

missinglinq
Expert 2.5K+
P: 3,532
After data is entered into the form and the record has been saved to table, the form clears and awaits a new record entry, however when attempting to exit the form thru an exit button, the validation check occurs because of no data in the field or fields.
The validation checks in the Form_BeforeUpdate will not occur simply because a "blank" new record has been displayed. The BeforeUpdate event will only fire if something has been entered into at least one of the fields, by either physically entering the data, or by assigning data to a control on a new record via code, such as assigning the current date to a field or assigning a generated ID number to the record..

If you have something like this coded, doing as NeoPa suggested, in your Exit code, with

If Me.Dirty Then Me.Undo

should solve the problem.


You might also check your code and make sure that you haven't put code in the OnExit or LostFocus event of a that first textbox you mentioned in your original post. Even on a new, non-dirtied record, code in either of these events will be fired when closing the form.

Linq ;0)>
Aug 30 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.