Results 1 to 7 of 7
  1. #1
    thompjas is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    13

    Struggling with a validation rule / before update

    Hi,

    aplogies if my first post seems 'basic' to the more advanced users of this forum, I have an Access form where I wish to ensure that of a checkbox is ticked I need the inputter to enter a number in a corresponding field.

    So..

    If Sub Location Field is ticked (i.e. True), then Reference field should not be empty (i.e. Null)

    I have tried a validation rule - this only worked when I deleted the reference field data and then tried to tab from it - on a new form I can leave this field blank and it 'skips past'



    So then I tried a before update event, but cannot seem to work out the code that is needed

    Any help greatfully received !!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps something like the following code in the Forms BeforeUpdate event
    Code:
    If Me.Location = True Then
      If IsNull(Me.Reference) Then
        Cancel = True
        MsgBox "Please enter Reference"
        Me.Reference.SetFocus
      End If
    End If 
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    thompjas is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    13
    Hi, thanks for the reply, this still allows the user to 'skip' entry of the reference field, though strangley if I add a value and then delete it the code prompts me to enter a reference number !

    Then I get an error



    Any ideas ??

    here is the code entered as a before update event in the forms design page

    Private Sub HOIDNumber_BeforeUpdate(Cancel As Integer)

    If Me.SubLocation = True Then
    If IsNull(Me.HOIDNumber) Then
    Cancel = True
    MsgBox "Please enter a Head Office ID Number"
    Me.HOIDNumber.SetFocus
    End If
    End If

  4. #4
    thompjas is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    13
    Sorry forgot screen shot or error message

    Click image for larger version. 

Name:	error messgae.png 
Views:	10 
Size:	5.5 KB 
ID:	19749

  5. #5
    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
    You didn't follow Bob's instructions!

    code in the Forms BeforeUpdate event
    You put your code in the Control's BeforeUpdate event; not the same thing!

    Private Sub HOIDNumber_BeforeUpdate(Cancel As Integer)

    needs to be

    Private Sub Form_BeforeUpdate(Cancel As Integer)

    Validation to see if a field is populated cannot be done in the Control's event for the very reason you gave...the user can simply 'skip' entry in the pertinent Control to foil the validation!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    thompjas is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    13
    Sorry, newbie mistake - now sorted - top bananas !!!

  7. #7
    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
    Quote Originally Posted by thompjas View Post
    ...Sorry, newbie mistake...
    Nothing to be sorry about...it's called learning!

    Glad we could help!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 2
    Last Post: 10-25-2012, 02:39 PM
  2. IIf in Validation Rule
    By Bugsy in forum Access
    Replies: 6
    Last Post: 11-21-2011, 11:33 AM
  3. Validation Rule
    By rbiggs in forum Forms
    Replies: 4
    Last Post: 08-23-2011, 05:24 PM
  4. Validation Rule
    By smitstev in forum Access
    Replies: 5
    Last Post: 06-30-2009, 09:58 AM
  5. Validation Rule
    By mistaken_myst in forum Database Design
    Replies: 2
    Last Post: 10-29-2007, 02:08 PM

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