Solved

How do I get code to run on subform?

Posted on 2011-03-25
2
273 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
Comment Utility
Try..

For Each Ctr In me.Controls
0
 

Author Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

728 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

9 Experts available now in Live!

Get 1:1 Help Now