Share via

Checking for missing data

Anonymous
2023-09-22T11:29:33+00:00

I am working on a form and all but 2 control is tagged as Required. I have the code below which checks for empty required fields. When it runs it starts checking with Question 1. Is there any way to get it to start with the first empty control? Tab order is set as it appears on the form.

Dim ctrl As Control

'Test for missing data 

    For Each ctrl In Me.Controls 

        If ctrl.Tag = "Required" Then 

          If IsNull(ctrl) Then 

              MsgBox "Incomplete form, Please fill in " & ctrl.Name, vbExclamation, "Invalid Operation" 

              Exit Sub 

          End If 

      End If 

    Next ctrl

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. George Hepworth 22,855 Reputation points Volunteer Moderator
    2023-09-22T13:14:38+00:00

    What difference in observed behavior would you anticipate from this modification? How do you even know, as a user, which control is checked first? If the first checked control is not null, doesn't the code move to the next control without offering any visual indication to the user that that has happened?

    Given the fact that performance differences would be so small as to be unnoticeable, how does it matter?

    Note, in addition, that to FIND the first "empty" control means somehow checking them all as the initial step anyway. How else would the code identify that control?

    If we understood the problem being addressed, though, maybe a possible approach could be suggested.

    Was this answer helpful?

    0 comments No comments