Solved

Check Access Form For Missing Data Programmatically

Posted on 2013-10-22
4
940 Views
Last Modified: 2013-10-22
I have created a form in Access 2007 with about 30 fields (employee information) that I would like to add some code to that can cycle through a number of fields to check if they have data in them. I want to be able to display message box that informs the user to enter data in the text box that is missing information.

Form is linked to a webservice that fills in 90% of the info for the user but there is still a bunch of fields that I want to ensure that have data. I began coding an if statement but it was way to much to type since it contained so many "OR"s and also I want to use the same code on other forms.

I am looking for some code that will cycle through a number of fields using maybe a LOOP and that opens a dialog box that specificlly names the fields that need to be filled in. If at all possible I would love for the code to be dynamic enough to using in other forms throughout the application.
Any assistance with this would be much appreciated. Thank you.
0
Comment
Question by:spaced45
  • 2
  • 2
4 Comments
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 500 total points
ID: 39593173
This is an example of how to highlight the empty required items in red.


 
Private Function CheckForRequiredItems(frm As Form) As Boolean
Dim cntrl As Control
CheckForRequiredItems = False
For Each cntrl In frm.Controls
    If InStr(cntrl.Tag, "Required") Then
        If IsNull(cntrl) Then
            cntrl.BackColor = 8421631
            CheckForRequiredItems = True
        Else
            cntrl.BackColor = 16777215
        End If
    End If
Next cntrl
End Function

Open in new window


To use the function, put Required in the required control's tag property then call it from the form's before update and unload events like this:

Private Sub Form_Unload ()
If CheckForRequiredItems(Me) Then
   MsgBox "The items in red are required"
   Cancel = True
End If
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:spaced45
ID: 39593187
Coach!! Worked like a charm! Thank you very much for all your assistance!!
0
 
LVL 1

Author Closing Comment

by:spaced45
ID: 39593188
Excellent solution
0
 
LVL 21
ID: 39593192
You're welcome.  Good luck with your project.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now