I think we need to step back and forget about the code for now.
Let's say you have 3 text box controls you want to have filled before saving. And let's say the first control is empty/null and the other two have entries.
There is a global boolean variable. "glblcancel", that when TRUE cancels the save and when FALSE allows the save. "glblcancel" defaults to FALSE when the form is opened.
So the first control is checked and, since the control is empty/null, glblcancel is set to TRUE.
The second control is checked and, since it has an entry, glblcancel is set to FALSE.
The third control is checked and, since it has an entry, glblcancel is set to FALSE.
Is this correct? No, since the first control is empty/null, the save should be canceled.
----------------------------------------------------------------------------
This is the code I would try: (air code - I modified your code)
Code:
For Each ctl In Me.Section("Detail").Controls
Select Case ctl.Tag
Case "Required;Check"
If Len(Trim(ctl.Value & "")) = 0 Then
ctl.BackColor = &HD0D0FF
glblcancel = True
Exit For
Else
ctl.BackColor = vbWhite ' or whatever your default backcolor is
glblcancel = False
End If
End Select
Next ctl
End Sub
The above code stops at the first control that is empty/null, so if you had 15 controls, you could have to click the save button 15 times (worst case )
This code snippet checks all controls, setting the BG color if the control is empty/null. Then is sets the global variable to TRUE/FALSE.
Code:
Dim Knt As Integer 'new declaration
.
.
Knt = 0
For Each ctl In Me.Section("Detail").Controls
Select Case ctl.Tag
Case "Required;Check"
If Len(Trim(ctl.Value & "")) = 0 Then
ctl.BackColor = &HD0D0FF
Knt = Knt + 1
Else
ctl.BackColor = vbWhite ' or whatever your default backcolor is
End If
End Select
Next ctl
If Knt = 0 Then
glblcancel = False
Else
glblcancel = True
End If
Hope this makes sense.......