Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I get code to run on subform?

Posted on 2011-03-25
2
Medium Priority
?
281 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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

650 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