Solved

How do I get code to run on subform?

Posted on 2011-03-25
2
274 Views
Last Modified: 2012-05-11
I have created an access database which uses forms for user data entry.  I have implemented validation coding
on the main form which works fine and highlights empty required fields that user has not filled out.  Save is not allowed
until the user finishes filling out all the fields.  On this form I have a subform which is linked to the main form by a case number.
I cant get the validation code to do the same thing on the subform.  When I open up the subform by itself the code
executes just fine, but when executed from within the subform I am not getting the same result.
Here is the code that I am using which works fine on the main form and on the subform when opened by itself. Any help and
insight would be appreciated. Thank you

Private Sub btnSaveClient_Click()
Dim strMsg As String, strTitle As String
   
   If ValidateFormComplete1 Then
        strMsg = "Do You Want To Save This Record?"
        strTitle = " Save Record ?"
                 If MsgBox(strMsg, vbQuestion + vbYesNo, strTitle) = vbNo Then
                    Me.Undo
                 Else
                    MsgBox "The case information has been saved. Proceed to enter defendant and plaintiff information below"
                 End If
                 Else
        MsgBox "The Small Claims Case Worksheet is not complete.  Please complete all highlighted fields"
            End If                  
End Sub

Private Function ValidateFormComplete1() As Boolean
Dim Ctr As Control
Dim FoundError As Boolean

FoundError = False
    For Each Ctr In Screen.ActiveForm.Controls
    Select Case Ctr.ControlType
        Case acComboBox, acTextBox, acCheckBox, acOptionBox
            If Ctr.Tag = "*" Then
                If IsNull(Ctr.Value) Or Ctr.Value = "" Then
                    Ctr.BackColor = RGB(223, 167, 165)
                    FoundError = True
                Else
                    Ctr.BackColor = RGB(255, 255, 255)
                End If
            End If
        End Select
        Next Ctr
ValidateFormComplete = Not FoundError
End Function

I believe the issue is most likely the referencing of the subform on the main form to get the code to execute
properly but I cant pinpoint it.  Thanks again
0
Comment
Question by:rgghost
2 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 35217291
Try..

For Each Ctr In me.Controls
0
 

Author Comment

by:rgghost
ID: 35217413
Exactly what I needed.  Tried it and  it worked like a charm.  Thank you so much Peter57r
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

820 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