Results 1 to 4 of 4
  1. #1
    elbartje is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    23

    Change the validation rules with VBA

    Hello all



    I wrote a code that checks the value typed into a combox is between the limits.

    I paste this into the on change event of the combobox:
    When for example the limits are 14-20 and you want to type 15 as soon as you type 1 an the error prompts.

    the code:

    If ComboBox.Value < Me!txtLowerLimit Or ComboBox.Value > Me!txtUperLimit Then
    MsgBox ("error")
    ComboBox.Value = ""
    End If

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    What is your question? What issue are you seeing?

    Why don't you use combobox ValidationRule property?

    I never allow empty strings in records. I would set combobox to Null.

    Probably need to set up validation rule to allow Null.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    The Change event fires on every keypress. You should use the BeforeUpdate event to validate the data entered - if it is not valid, then set Cancel = True after your message display.

  4. #4
    elbartje is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    23
    Thank you for the help that is what I needed!

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

Similar Threads

  1. Validation Rules
    By hinkwale in forum Access
    Replies: 2
    Last Post: 01-21-2015, 07:06 PM
  2. Validation Rules Help
    By Troop in forum Access
    Replies: 11
    Last Post: 03-05-2013, 01:26 PM
  3. Validation Rules in the Forms
    By JoeyHenry in forum Access
    Replies: 1
    Last Post: 02-04-2013, 05:07 PM
  4. Field rules/validation rules
    By sk88 in forum Access
    Replies: 14
    Last Post: 02-26-2012, 01:03 PM
  5. Validation Rules
    By esglover in forum Database Design
    Replies: 1
    Last Post: 07-23-2010, 08:02 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