I have a db with many forms which each have a number of mandatory fields. I need a generic function to display an error message if the user either tabs through the field(s) without entering any data, or tries to close the form without entering the data. I am using the following code to call the MandatoryField function from a module. This works exactly as expected.
However, what I really need to display in the message box is the Caption of the field’s associated label. So I need to pass to the Function the field’s Labelname. All my attempts to do so have ended in abject failure.
I tried
and get an “Object Required” error. I tried declaring a control variable and passing that, but got the error message “Object variable or With Block variable not set”.
Can anybody tell me how to amend this code to send the control’s labelname to the function? All the fields’ labels are named using the convention FieldNameLabel.
TIA
__________________________________________________________
___________________________________________________________
This function really needs to be:
__________________________________________________________
Lightning
However, what I really need to display in the message box is the Caption of the field’s associated label. So I need to pass to the Function the field’s Labelname. All my attempts to do so have ended in abject failure.
I tried
Code:
Call MandatoryField(Me.ActiveControl & “Label”)
Can anybody tell me how to amend this code to send the control’s labelname to the function? All the fields’ labels are named using the convention FieldNameLabel.
TIA
__________________________________________________________
Code:
Private Sub SupportNames_Exit(Cancel As Integer)
If IsNull(SupportNames) Then
Call MandatoryField(Me.ActiveControl)
Cancel = True
Call ChangeColor
LocalSupport.SetFocus
End If
End Sub
Code:
Public Function MandatoryField(ctl As Control)
Dim strField As Variant
strField = MsgBox(ctl.Name & "@This field MUST have information entered into it.@" & _
"Enter the required information or press the [ESCAPE] key Twice to delete " & _
"all data on this screen and start again.", vbOKOnly + vbInformation, _
"Required Information Missing!!")
End Function
This function really needs to be:
Code:
Public Function MandatoryField(ctl As Control)
Dim strField As Variant
strField = MsgBox(ctl.Caption & "@This field MUST have information entered into it.@" & _
"Enter the required information or press the [ESCAPE] key Twice to delete " & _
"all data on this screen and start again.", vbOKOnly + vbInformation, _
"Required Information Missing!!")
End Function
Lightning