Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    Multiple validations

    I have three textboxes for data entry. If they ALL = 0 then I want a message box. If ANY of them have a value then I want the code to continue.



    I can do this myself but probably not elegantly.

    Would these be dealt with individually with three separate if scenarios or is there a way of doing this in one piece of code?

    I understand this isn't a necessity its just my OCD and a chance to understand some more VBA

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    What code to continue? Your post is really lacking in details.

    When, for example, do you want the validation to be done and the warning to pop...just before saving a Record?

    Presumably your Record has other Controls, as well, and if the above guess is correct, you do the validation in the Form_BeforeUpdate event:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
     If Me.TextboxA + Me.TextboxB + Me.TextboxC = 0 Then
      MsgBox "All Three Textboxes are Empty!"
      Cancel = True
     End If
    End Sub

    IF the above guess, isn't correct, you'll need to give a more detailed explanation of what you're trying to do.

    Linq ;0)>

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    This code in the forms BeforeUpdate event does what you asked for:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)    If Me.one = 0 And Me.two = 0 And Me.three = 0 Then
            MsgBox "this is your msg"
            Cancel = True 'This stops the form from updating
        End If
    End Sub
    However, if any of the boxes a ZLS you would need this code:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)    If Nz(Me.one, 0) = 0 And Nz(Me.two, 0) = 0 And Nz(Me.three, 0) = 0 Then
            MsgBox "this is your msg"
            Cancel = True 'This stops the form from updating
        End If
    End Sub
    Edit:
    Sorry. didn't notice that Linq had already replied
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    There is no code yet. I thought I would ask before I started. But your answer seems to be exactly what I'm after. Ill have a go.

  5. #5
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thanks both. Worked fine and default value is zero so no problems.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multiple users with validations
    By ajax1234 in forum Access
    Replies: 1
    Last Post: 09-19-2016, 01:06 AM
  2. Property sheet validations
    By thisisjess in forum Access
    Replies: 2
    Last Post: 08-26-2015, 12:42 PM
  3. Can you have 'Multiple Validations' in one Field
    By euphonium01 in forum Access
    Replies: 6
    Last Post: 10-17-2013, 12:00 PM
  4. Multiple validations in same field
    By UTS in forum Queries
    Replies: 1
    Last Post: 09-06-2011, 09:51 AM
  5. Validations
    By Icewolf0927 in forum Forms
    Replies: 1
    Last Post: 09-24-2010, 09:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums