Results 1 to 3 of 3
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    237

    Replace default access error messages


    Hi,
    I have eleven required fields on a form. I am trying to replace the default error message generated by access. I am trying to use the Form's Error() Event.
    I found examples for several cases; like four different errors for four different fields, each field has its different error message.
    I could not find example of the same error 3314 (field is required) for different fields. Is it possible to have a different error message for each field ?


    Khalil

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Quote Originally Posted by Khalil Handal View Post
    Hi,
    I have eleven required fields on a form. I am trying to replace the default error message generated by access. I am trying to use the Form's Error() Event.
    I found examples for several cases; like four different errors for four different fields, each field has its different error message.
    I could not find example of the same error 3314 (field is required) for different fields. Is it possible to have a different error message for each field ?


    Khalil
    It appears you are trying to do data validation, making sure that each of the 11 required fields have been filled in.
    What do you mean by "A different error message for each field" Do you want the error message to identify the offending field?

    One way to validate multiple fields is to use the controls tag property and loop through the form controls to check for missing data.
    Normally this is done in the before update event or before a procedure is run.

    I prefer one message box to include all missing fields and also changing the control bordercolor to red to highlight it.

    I use the following function which returns true if fields are empty
    Code:
    Public Function ValidateForm(frm As Form, TagCharacter As String) As Boolean
    'validated controls must have a label. Ok to use a hidden label if needed.
    'Returns True if missing Data
    
    
        Dim ctl As Control
        Dim flg As Boolean
        Dim strOut As String
    
    
        flg = False
    
    
        For Each ctl In frm.Controls
    
    
            If ctl.Tag = TagCharacter Then
                If Nz(ctl.value, "") = "" Then
                    flg = True
                    ctl.BorderColor = vbRed
                    strOut = strOut & Space(10) & "* " & ctl.Controls.Item(0).Caption & vbNewLine
                Else
                    ctl.BorderColor = vbBlack
                End If
    
    
            End If
        Next
    
    
        If flg = True Then
            MsgBox "The following field(s) must be completed:" & vbNewLine & strOut
        End If
    
    
        ValidateForm = flg
    
    
    End Function
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jun 2016
    Posts
    237
    Hi,
    Thank you for your reply.
    By "A different error message for each field" I mean that if field1 is a birth date, the message should say :" please enter birth date", If field2 is a name, the message is :"please enter your name".
    The function you mentioned will change ALL controls to red weather they are required fields or not. My form has some fields that might not be filled with data.
    I will try your function and keep you posted.

    What is the syntax to be used in the before_Updae Event ?

    Khalil


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

Similar Threads

  1. Replies: 14
    Last Post: 05-31-2020, 10:50 AM
  2. How can I make Access not show error messages?
    By securitywyrm in forum Access
    Replies: 16
    Last Post: 01-31-2018, 09:44 PM
  3. Error Messages On Subforms, Access 2016
    By roxdrob in forum Forms
    Replies: 19
    Last Post: 10-07-2017, 11:40 PM
  4. Setting access runtime default find/replace behavior
    By SepieSmith in forum Programming
    Replies: 9
    Last Post: 11-05-2015, 03:53 AM
  5. Custom messages to Access' default error messages.
    By evander in forum Programming
    Replies: 1
    Last Post: 06-26-2010, 02:06 AM

Tags for this Thread

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