Results 1 to 2 of 2
  1. #1
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    fiield validation rules

    Hi

    question 1 : do you ever finish a database? ;-)

    Question 2:

    I have a text field named "txtYearOfBaptism" which I use to create a temporary variable based on the year typed in by the user.

    I was using the database and trying to break it when I realised that if in error I input fred instead of 1829 the database did horrible things so decided it need a validation rule.

    So I went to field properties validation rule expecting to be able to create some vba code/ or a macro to display a message box - This field requires a numerical value ie 1878

    However the validation option only seems to bring up the expression builder which I have no experience of.

    I then realized that as I was using a button to create my temporary variable I could possibly add some vba here.

    But as I'm not at all sure which way to go thought I'd ask!



    Button code below

    thanks

    Ian

    Code:
    Private Sub btn_Search_baptismyear_Click()
    TempVars!varBaptismYear = Me.txtYearOfBaptism.Value
        If DCount("*", "qry_BaptismsYearSearch") > 0 Then
        DoCmd.Close
        DoCmd.OpenForm "frm_BaptismYearSearchResults", acNormal, "", "", , acNormal
    Else: MsgBox "There are no Baptism Records containing this Year"
    TempVars.Remove "varBaptismYear"
        End If
    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Normally you would validate control entries in the Before Update event of the control. You can set Cancel = True and display a message if there is something in the entry that needs fixing. Setting Cancel = True will hole the cursor in the current control.

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. Field rules/validation rules
    By sk88 in forum Access
    Replies: 14
    Last Post: 02-26-2012, 01:03 PM
  4. troubles with validation rules
    By focosi in forum Access
    Replies: 4
    Last Post: 08-02-2011, 10:46 AM
  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