Hi everybody,
This may be an easy one, but I'm having a lot of trouble with it. I have a continuous form and I want to validate that the user has entered something in each of the required fields in the BeforeUpdate event for the form.
This I can do...the fun part is that I want to do it in reverse so that when I call the SetFocus method, it goes to the first control that is empty as opposed to the last one.
To loop forward, I've used the For Each...Next loop, but as far as I know this can't be used to loop backwards. Here's my code:
On line 5, I'd like for (last) to be first empty control.
Thanks for the help...
This may be an easy one, but I'm having a lot of trouble with it. I have a continuous form and I want to validate that the user has entered something in each of the required fields in the BeforeUpdate event for the form.
This I can do...the fun part is that I want to do it in reverse so that when I call the SetFocus method, it goes to the first control that is empty as opposed to the last one.
To loop forward, I've used the For Each...Next loop, but as far as I know this can't be used to loop backwards. Here's my code:
Code:
nullMsg = "You need to enter a value in: " & Chr(13) 'Message for msgbox
nullTitle = "Value Required" 'Title for msgbox
For Each ctl In Controls 'Loop through all the controls on (current) form
'If the control is empty and not equal to the tags specified then concatenate a string to nullMsg to notify the user. Then set the focus to the (last) empty control
If IsNull(ctl) And (ctl.Tag <> "Corrected Date") And (ctl.Tag <> "Progress Note ID") Then
controlName = controlName + (ctl.Tag & Chr(13))
ctl.SetFocus
End If
Next ctl
If Me.FormIDFK = 36 And IsNull(Me.ProgressNoteIDFK.Value) Then
controlName = controlName + (Me.ProgressNoteIDFK.Tag & Chr(13))
End If
If Not IsEmpty(controlName) Then
MsgBox nullMsg & controlName, vbExclamation, nullTitle
Cancel = True
End If
Thanks for the help...
Comment