Changing default text in content control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tsnave
    New Member
    • Jul 2013
    • 15

    Changing default text in content control

    I am importing data from content controls in Word to Access 2010. When the data is imported, "Click here to enter text" shows up in the DB table. This is when a user leaves that content control empty on the Form. I would like to Have "n/a" show up in the DB table. The code I am using is working for some DB fields but not all. Here is a sample:
    Code:
     Case "CP Goal"
                    If cc.Range.Text <> cc.PlaceholderText Then
                    cpGoal = cc.Range.Text
                    Else: cpGoal = "n/a"
                    End If
                Case "1st Focus Sector"
                    If cc.Range.Text <> cc.PlaceholderText Then
                    firstFocSec = cc.Range.Text
                    Else: firstFocSec = "n/a"
                    End If
    I am using the Title of the content controls to gather the user input.

    Any suggestions would be great.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You said it works for some but not others. We would need to know which ones you're talking about.

    Comment

    • tsnave
      New Member
      • Jul 2013
      • 15

      #3
      Here are the ones it doesn't work with. When I use the cc.PlaceholderT ext, I get an error. The error is 91:Object Variable or With Block not Set.

      Code:
       Case "PS Name of School or Program"
                      If cc.Range.Text <> "Click here to enter text" Then
                      psNameOfSchool = cc.Range.Text
                      Else: psNameOfSchool = "n/a"
                      End If
      Case "CA Activity"
                      If cc.Title = "CA Activity" Then
                      caActivity = cc.Range.Text
                      Else: caActivity = "n/a"
                      End If
                  Case "CA Facilitator"
                      If cc.Title = "CA Facilitator" Then
                      caFacilitator = cc.Range.Text
                      Else: caFacilitator = "n/a"
                      caFacilitator = "n/a"
                      End If
                  Case "CA Follow-up Activity"
                      If cc.Title = "CA Follow-up" Then
                      caFollowUp = cc.Range.Text
                      Else: caFollowUp = "n/a"
                      End If
                  Case "CA Freq of Activity"
                      If cc.Title = "CA Freq of Activity" Then
                      caFreqOfActivity = cc.Range.Text
                      Else: caFreqOfActivity = "n/a"
                      End If
      Case "Noteable CP Interventions and Outcomes"
                      If cc.Title = "Noteable CP Interventions and Outcomes" Then
                      noteableCPIntervAndOutcomes = cc.Range.Text
                      Else: noteableCPIntervAndOutcomes = "n/a"
                      End If
      Using the cc.Title statement got me passed the error, but the default text still comes in instead of "n/a"

      Thanks

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        The error likely means that whichever control you're trying to access doesn't have a PlaceholderText property. So you're trying to use something that doesn't exist. But that's just a guess, you haven't given us enough information to say either way. We would need to know how cc is set for example. We would also need to know what controls are being used.

        Comment

        • tsnave
          New Member
          • Jul 2013
          • 15

          #5
          The document given to me is a template made by someone else. I'm not sure about the PlaceHolderText Property. The cc is set up in a loop to go through each content control and the controls are plain text:

          Code:
          For Each cc In doc.ContentControls
                  ccInfo = "<> ID= " & cc.ID & " Title = " & cc.Title & " Text = " & cc.Range.Text & vbCrLf
                  Debug.Print ccInfo
                  Select Case cc.Title:
          And then my Case statements are like what I submitted in previous post.

          Thank you

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            My guess was probably right. The control that it's using doesn't have the PlaceholderText property or it doesn't have it set. You'll just need to check the controls where you have the error to see whether or not it is set or whether it even exists. Not every control has that property.

            Comment

            • tsnave
              New Member
              • Jul 2013
              • 15

              #7
              Thank you for your help. I will try to find out where to see if the PlaceholderText Property is set or exists.

              Comment

              • tsnave
                New Member
                • Jul 2013
                • 15

                #8
                I have found a solution to my problem. Here is a sample of the code that replaces the default "Click here to enter text", from a plain text content control, with "n/a" in an Access DB:
                Code:
                 Case "Agency Name"
                                 If cc.ShowingPlaceholderText = False Then
                                 agencyName = cc.Range.Text
                                 Else: agencyName = "n/a"
                                 End If
                
                Thank you for all the help and I hope this solution will help others as well.

                Comment

                Working...