Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Check Access Form For Missing Data Programmatically

Posted on 2013-10-22
4
Medium Priority
?
993 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 2000 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

688 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