Data Validation 'Tag Method'

UPDATE: After adding a second "End If", it now works correctly! I still have to do a few more tests to make sure. Don't have the time at this second. Will follow-up to update this post with the final determination.

The final code looks like

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Cancels Update if required fields are missing.
'if fields are missing, It will  create a popup message explaining which fields need data
' Form is saved and closed if all required fields have data
 Dim strError As String
Dim ctl As Control
Dim blnIsValid As Boolean
 strError = "Validation failed for the following reasons: " & vbNewLine
blnIsValid = True
 For Each ctl In Me.Controls
    With ctl
        Select Case ctl.ControlType
            Case acTextBox, acComboBox, acListBox, acCheckBox, acOptionButton, acOptionGroup, acToggleButton
                'If .Tag = "Required" Then
                'If .Value & "" = "" Then
                If Nz(.Tag) = "Required" Then
                If Nz(.Value) = "" Then
                    blnIsValid = False
                    strError = strError & "   - " & ctl.Name & " is required" & vbNewLine
                End If
                End If
        End Select
    End With
Next ctl
 If blnIsValid = False Then
    'Form data is NOT valid!
    Cancel = True 'Cancel the update
    MsgBox strError, vbInformation
End If
 Set ctl = Nothing
    'EMAIL CODE HERE
    'EXCEL COE HERE
    Me!EditedWhen = Now()
    
End Sub

Edit: confirmed this is working as intended! Thank you so much, Fuse3k, for putting up with my constant issues and for replying so quickly,
 
Last edited:
Glad to hear it! Please click Thank button if it was helpful :)
 

Users who are viewing this thread

Back
Top Bottom