coasterman
Registered User.
- Local time
- Today, 12:14
- Joined
- Oct 1, 2012
- Messages
- 59
Is it possible to use Like when comparing the value in a ctl.Tag
I am trying to adapt the following validation routine so that it can be put behind a number of different command buttons to test for a different string in the tag property of the control. The code would be copied replacing the required string from the tag property, the example below is "*" but would of course be changed to some other string for subsequent cmd buttons.
Validation requirements vary on this form so for instance, and much simplified:
Scenario 1
Txt1 ,Txt2,Txt3,Txt4 need data
Scenario 2
Txt2, Txt3 need data
I was thinking if I could add two or more different values in the tag property and use Like I could validate only the controls needed from each cmd button.
If I change '=' to 'Like' in the following routine it finds an empty field (with no tag property) on another page of my Tab ctrl.
Is this a simple fix or am I getting into something rather more complex? I guess I need some way of having the code ignore ctrl's with no tag property value entered and still have the functionality of testing for Like?
Thanks for looking
I am trying to adapt the following validation routine so that it can be put behind a number of different command buttons to test for a different string in the tag property of the control. The code would be copied replacing the required string from the tag property, the example below is "*" but would of course be changed to some other string for subsequent cmd buttons.
Validation requirements vary on this form so for instance, and much simplified:
Scenario 1
Txt1 ,Txt2,Txt3,Txt4 need data
Scenario 2
Txt2, Txt3 need data
I was thinking if I could add two or more different values in the tag property and use Like I could validate only the controls needed from each cmd button.
If I change '=' to 'Like' in the following routine it finds an empty field (with no tag property) on another page of my Tab ctrl.
Code:
Private Sub cmdValpgGeneral_Click()
Dim msg As String, Style As Integer, Title As String
Dim nl As String, ctl As Control
nl = vbNewLine & vbNewLine
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
If ctl.Tag = "*" And Trim(ctl & "") = "" Then
msg = "Data Required for '" & ctl.Name & "' field!" & nl & _
"You can't save this record until this data is provided!" & nl & _
"Enter the data and try again . . . "
Style = vbCritical + vbOKOnly
Title = "Required Data..."
MsgBox msg, Style, Title
ctl.SetFocus
Cancel = True
Exit For
End If
End If
Next
End Sub
Is this a simple fix or am I getting into something rather more complex? I guess I need some way of having the code ignore ctrl's with no tag property value entered and still have the functionality of testing for Like?
Thanks for looking
Last edited: