Question : Validation Messages

Currently, I have my validation set up so then it concatinates a string and then gives a message of all the fields that aren't filled in all at once on the BeforeUpdate event.  Here is the code:

        Dim valMessage As String
        Dim valInvolvement As String
        Dim valFirstName As String
        Dim valLastName As String

        valMessage = ""

        If IsNull(Me.txtInvolvement.Value) Then
            valMessage = valMessage & "Involvement, "
        End If

        If IsNull(Me.txtFirstName.Value) Then
            valMessage = valMessage & "First Name, "
        End If

        If IsNull(Me.txtLastName.Value) Then
            valMessage = valMessage & "Last Name, "
        End If

        If Len(valMessage) > 0 Then
            MsgBox valMessage & "must be filled out before a Person can be saved."
            Cancel = True
            Exit Sub
        End If

The error message will look like this:

Involvement, First Name, Last Name, must be filled out before a Person can be saved.
But what I'd like the message to look like is this:

These fields must be filled out before a person can be saved:

Involvement
First Name
Last Name


Where it lists all the fields on their own line.  Any advice on how to do this?

Answer : Validation Messages

Use vbCRLF as to put a carraige return and line feed between these.

       Dim valMessage As String
        Dim valInvolvement As String
        Dim valFirstName As String
        Dim valLastName As String

        valMessage = ""

        If IsNull(Me.txtInvolvement.Value) Then
            valMessage = valMessage & "Involvement" & crlf
        End If

        If IsNull(Me.txtFirstName.Value) Then
            valMessage = valMessage & "First Name" & crlf
        End If

        If IsNull(Me.txtLastName.Value) Then
            valMessage = valMessage & "Last Name" & crlf
        End If

        If Len(valMessage) > 0 Then
            MsgBox "These field(s) must be filled out before a Person can be saved:" & crlf & crlf & valMessage
            Cancel = True
            Exit Sub
        End If
Random Solutions  
 
programming4us programming4us