View Single Post
 
Old 02-28-2024, 02:35 AM
viewtost viewtost is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jul 2021
Posts: 35
viewtost is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
It doesn't matter if you aren't great with macros - there is plenty of resources available and threads here to help you learn.

I can't give you a direct answer because you haven't been clear on what you 'want'. This is a good thing because it shows you are trying to learn but it also means we can't jump to a complete solution without considering the larger picture.

Food for Thought: If you are going to validate a 'completed' form then you need to work out what constitutes completed. Does EVERY CC need to be completed or just some of them? If your code identifies a CC that needs completing, how does it inform the user where that CC is? When should the code run?

Here are some threads which are worth studying:
https://www.msofficeforums.com/word/...completed.html
https://www.msofficeforums.com/word-...-vba-code.html
https://www.msofficeforums.com/word-...ault-text.html

Hi, thanks for your help.

Sorry if I haven't been clear on what I want to achieve with this macro. Basically, I have a form, and I would like the person filling it out not to leave any section blank. That's why I am inserting a text content control for each section of the form. If the user leaves any section blank, a message will pop up warning them. If they are not blank, I want the user to receive a message indicating that there is content in the fields.

I have tried using an array, and made sure the names are the same as the ones I have given to the content controls, but I am getting the error "Run time error 13 Type mismatch," so I'm not sure what's causing it.


Code:
Sub CheckAllContentControls()

  Dim aCC As ContentControl
  Dim ctrlTitle() As String  ' Array to store control titles

  ' Define the list of control titles
  ctrlTitle = Array("Name", "Position", "Store", "Date of Lateness", _
                   "Scheduled Time Lost", "Number of occurrences in 13 weeks", _
                   "Number of occurrences in 52 weeks", "Stage", "Details", _
                   "Is there any pattern", "Preventative measures", "Employee signature", _
                   "Employee signature date", "Employee name", "Managers signature", _
                   "Managers signature date", "Managers name")

  ' Loop through all control titles
  For i = 0 To UBound(ctrlTitle)
    ' Check each content control with the current title
    For Each aCC In ActiveDocument.SelectContentControlsByTitle(ctrlTitle(i))
      If aCC.ShowingPlaceholderText Then
        MsgBox "The Content Control '" & ctrlTitle(i) & "' is Empty"
      Else
        MsgBox "The Content Control '" & ctrlTitle(i) & "' has content"
      End If
    Next aCC
  Next i

End Sub
Thanks!
Reply With Quote