zeroaccess
Active member
- Local time
- Yesterday, 18:27
- Joined
- Jan 30, 2020
- Messages
- 671
Hey all,
I am doing a validation check based on null fields and setting the border color if true. The following works well:
But I needed to also loop through subform controls, so after much wrangling, I came up with this:
I'm happy to say this also works, however observing the following quirks:
When there is only 1 subform record, the message box comes up twice - first after setting the subform fields red, then again after it acts on the main form (why in that order, I don't know).
When there are multiple subform records, it will only turn them red if I first click down into one of the subform fields, and then it works, but the message box does not appear.
Strange. I'm sure I have something wonky in my code.
The subform is a continuous form so unfortunately all of the records for a particular field or column will be outlined in red, but it will at least draw the user's attention to the right area.
Anyway, I need to figure out how to get the message to pop only once and I'm going to also try to set focus. It would be nice if I could act on the whole form and not in separate parts - I think that would solve these issues.
I am doing a validation check based on null fields and setting the border color if true. The following works well:
SQL:
Function ValidateInspection()
Dim ctrl As Control
For Each ctrl In Forms.frmInspection.Controls
Select Case ctrl.Tag
Case "ValidateID", "ValidateSD"
If IsNull(ctrl) Then
ctrl.BorderColor = vbRed
Else
Exit Function
End If
End Select
Next
MsgBox "Please enter missing data.", vbCritical
End Function
But I needed to also loop through subform controls, so after much wrangling, I came up with this:
SQL:
Function ValidateInspection(frm As Form)
Dim ctrl As Control
For Each ctrl In frm
Select Case ctrl.ControlType
Case acComboBox, acTextBox
Select Case ctrl.Tag
Case "ValidateID", "ValidateSD"
If IsNull(ctrl) Then
ctrl.BorderColor = vbRed
Else
Exit Function
End If
End Select
Case acSubform
ValidateInspection frm(ctrl.Name).Form
End Select
Next
MsgBox "Please enter missing data.", vbCritical
End Function
I'm happy to say this also works, however observing the following quirks:
When there is only 1 subform record, the message box comes up twice - first after setting the subform fields red, then again after it acts on the main form (why in that order, I don't know).
When there are multiple subform records, it will only turn them red if I first click down into one of the subform fields, and then it works, but the message box does not appear.
Strange. I'm sure I have something wonky in my code.
The subform is a continuous form so unfortunately all of the records for a particular field or column will be outlined in red, but it will at least draw the user's attention to the right area.
Anyway, I need to figure out how to get the message to pop only once and I'm going to also try to set focus. It would be nice if I could act on the whole form and not in separate parts - I think that would solve these issues.
Last edited: