?
Solved

How do I get code to run on subform?

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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

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…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

765 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