Solved

How do I get code to run on subform?

Posted on 2011-03-25
2
276 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
[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 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…

726 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