• Keep FormField contents on 1 line (WinXP NL / Off2003 NL)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Keep FormField contents on 1 line (WinXP NL / Off2003 NL)

    Author
    Topic
    #416165

    In a paragraph there are a few FormFields (FF) to be filled out by an end-user. One of the FFs is a datefield, formatted as “dd-MM-yyyy”. Sometimes there’s no room on a line to hold the complete date and FF is abbriviated. The users don’t like that. Is there a (preferably easy) way to make sure this date FF is not abbreviated and kept together on one (the next) line?

    Viewing 1 reply thread
    Author
    Replies
    • #929950

      Hi Jan

      You can put the date field inside an EQ field as shown in post 409788

      • #929952

        Nice idea (I thought of it too grin), but the user won’t be able to enter anything in the form field if it is inside an EQ field sad

        • #929955

          Good point, I have used the method with date fields before but never with form fields. Should have tested it first. stupidme

    • #929957

      Unfortunately, I can’t think of a way to do this. The .TextInput.Format property of a form field is read-only, so you can’t replace the hyphens in the date format with non-breaking hyphens.
      Instead of using form fields, you could create a UserForm (in VBA) to let the users enter the date (and other information). You can then place the date in the document with non-breaking hyphens.

      • #929960

        Thanks Hans. I was afraid of that. sad

        But I came up with the idea of an ExitMacro using Selection.Information(wdVerticalPositionRelativeToPage). If this is different for the first and last position in the FFs contents, then it’s split over 2 lines. And that could be solved by putting a soft return just in front of the FF. I have to work it out in detail, but I there are possibilities, I think.

        • #929966

          I have it working. And a lot easier than I thought up front. There’s a FormField named Date_exp (expiration) in a paragraph of the doc that needs to be on 1 line. Chr(11) is a soft return (Shift+Enter). ProtectionOff and ProtectionOn are custom Subs that do what their names suggest…

          Public Sub ExitDate_exp()
          Dim dblStart  As Double
          Dim dblEnd    As Double
          Dim dblLength As Double
          
              dblLength = Len(ActiveDocument.FormFields("Date_exp").Result)
              With Selection
                  .GoTo What:=wdGoToBookmark, Name:="Date_exp"
                  dblStart = .Information(wdVerticalPositionRelativeToPage)
                  .MoveRight Count:=dblLength
                  dblEnd = .Information(wdVerticalPositionRelativeToPage)
                  If dblStart  dblEnd Then
                      .GoTo What:=wdGoToBookmark, Name:="Date_exp"
                      .Collapse Direction:=wdCollapseStart
                      .MoveLeft
                      ProtectionOff
                      .InsertBefore Chr(11)
                      ProtectionOn
                  End If
              End With
          End Sub 
          • #929967

            Thanks for sharing. What happens if the user edits the document later on in such a way that there is enough room for Date_exp on the line above?

            • #929968

              Good question! grin
              Thanks for pointing that out. For now I think I’ll put the Chr(11) inside the FF (by omitting the last .MoveLeft). Then the users can manually correct it if necessary. That buys me some time to fix this properly, because they want this asap.

            • #929971

              I got it right this time…
              I removed the last .MoveLeft so that the Chr(11) is inserted as the first character into the FormField.
              Then added to the top of the Sub a test to see if the first character of the content of the FormFiled is a Chr(11) and if so, remove it and replace the old content with the new one. Anything else I missed Hans? grin

              Public Sub ExitDate_exp()
              Dim dblStart  As Double
              Dim dblEnd    As Double
              Dim dblLength As Double
              Dim strTemp   As String
              
                  strTemp = ActiveDocument.FormFields("Date_exp").Result
                  If Left(strTemp, 1) = Chr(11) Then
                      strTemp = Mid(strTemp, 2)
                      ActiveDocument.FormFields("Date_exp").Result = strTemp
                  End If
                  dblLength = Len(ActiveDocument.FormFields("Date_exp").Result)
                  With Selection
                      .GoTo What:=wdGoToBookmark, Name:="Date_exp"
                      dblStart = .Information(wdVerticalPositionRelativeToPage)
                      .MoveRight Count:=dblLength
                      dblEnd = .Information(wdVerticalPositionRelativeToPage)
                      If dblStart  dblEnd Then
                          .GoTo What:=wdGoToBookmark, Name:="Date_exp"
                          .Collapse Direction:=wdCollapseStart
                          ProtectionOff
                          .InsertBefore Chr(11)
                          ProtectionOn
                      End If
                  End With
              End Sub
              
            • #929973

              The only thing I can think of is that if you have other form fields before Date_exp in the same paragraph, you may have to do this in their On Exit macro too – the position of Date_exp might shift if those form fields are edited. If there are no form field before Date_exp in the same paragraph, there is no problem.

            • #929975

              There are other FormFields in the same paragraph, but according to the end-users I’ve talked to, the described problem doesn’t apply to them, only to this date FormField.
              thankyou Hans!

            • #929977

              What I meant was that the Date_exp form field might end up in a different position on the line if form fields before it are modified. You won’t catch that with the On Exit macro of Date_exp.

            • #929978

              Ah, I see what you mean now. But I don’t think this is much of a problem, because our users are very well trained to jump out of every FormField with a Tab… innocent

            • #929979

              If the users always tab into and out of Date_exp while editing, it should be OK.

    Viewing 1 reply thread
    Reply To: Keep FormField contents on 1 line (WinXP NL / Off2003 NL)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: