Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check Access Form For Missing Data Programmatically

Posted on 2013-10-22
4
Medium Priority
?
1,000 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

971 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