Results 1 to 13 of 13
  1. #1
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word Form Unhide Text (VB 6.3)

    I am trying to set up a Word form that will display the credit card fields if a field called "charge" is checked. The fields below the charge checkbox are formatted as hidden text. I am a very novice user and have part of my macro set up, but I am getting an error. Wondering if one of the helpful folks here will help me figure out the error of my ways!

    Here's the code right now:

    Sub charge()

    If ActiveDocument.FormFields("Check1").Result = True Then
    ActiveDocument.Unprotect Password:=""

    ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
    ShowAll
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveDown Unit:=wdLine, Count:=6, Extend:=wdExtend
    With Selection.Font

    .Hidden = False

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    ActiveDocument.FormFields("Check1").Result = False

    End If

    End Sub


    When I check the charge field and tab away, I get the following error: Compile Error: End If without block If

    I'm not even sure if the rest is OK, because I can't get past that error! Thanks for helping! <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30>
    egghead

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word Form Unhide Text (VB 6.3)

    The error message is somewhat confusing. The actual error in your code is that you don't have a line <code>End With</code> to match the line <code>With Selection.Font</code>.
    You should insert <code>End With</code> immediately below the line <code>.Hidden = False</code>.

  3. #3
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Form Unhide Text (VB 6.3)

    Thank you! That worked, as you knew it would!!

    Can I ask anothe question, then? After the fields are unhidden, the charge checkbox reverts to being unchecked. I've tried changing the last two lines to "false" and "true" with no effect.

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    ActiveDocument.FormFields("Check1").Result = False

    Here's the entire code:


    Sub charge()

    If ActiveDocument.FormFields("Check1").Result = True Then
    ActiveDocument.Unprotect Password:=""

    ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
    ShowAll
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveDown Unit:=wdLine, Count:=7, Extend:=wdExtend
    With Selection.Font

    .Hidden = False

    End With

    ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
    ShowAll

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    ActiveDocument.FormFields("Check1").Result = False

    End If

    End Sub
    egghead

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word Form Unhide Text (VB 6.3)

    To set the check box to "checked", use
    <code>
    ActiveDocument.FormFields("Check1").CheckBox.Value = True
    </code>
    and to set the check box to "clear", use <code>... = False</code>

  5. #5
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Form Unhide Text (VB 6.3)

    Thanks again!

    I can delete this line then?
    ActiveDocument.FormFields("Check1").Result = False

    Can you explain the difference?
    egghead

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word Form Unhide Text (VB 6.3)

    Yes, you can delete that line.
    Result is for form text boxes and form dropdown boxes. Although the property also exists for form check boxes, it can only be used to read the value, not to set it. You must use the Checkbox property for that.

  7. #7
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Form Unhide Text (VB 6.3)

    I am trying to do another macro similar to this earlier one. This is for a dropdown. When the value "lease" is picked from the dropdown, another hidden text paragraph should display. I had it working, except the nonprinting characters stayed on. When I fiddled with the code I managed to break the macro. Now it does absolutely nothing!! <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

    Here's what I have--any ideas? TIA

    Sub Lease()

    If ActiveDocument.FormFields("dropdown2").Result = "lease" Then
    ActiveDocument.Unprotect Password:=""

    ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
    ShowAll
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
    With Selection.Font

    .Hidden = False
    End With

    ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
    ShowAll

    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
    ActiveDocument.FormFields("dropdown2").Result = "lease"
    End If

    End Sub
    egghead

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word Form Unhide Text (VB 6.3)

    Here is a cleaned up version of the macro.

    Sub Lease()
    If ActiveDocument.FormFields("dropdown2").Result = "lease" Then
    ActiveDocument.Unprotect
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
    Selection.Font.Hidden = False
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    End If
    End Sub

    Are you sure that the current selection is in the correct place when the macro is run?

  9. #9
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Form Unhide Text (VB 6.3)

    I'm not sure what you mean about the current selection in the correct place. The drop down is in one paragraph. The hidden text is in the next paragraph below.

    I copied and pasted your text in and it still didn't do anything. I deleted mine and recreated it , still does nothing.
    egghead

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word Form Unhide Text (VB 6.3)

    Can you post a copy of the document? You can remove most of the text, as long as the dropdown and a couple of paragraphs below it remain. Replace sensitive text with dummy text.

  11. #11
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Form Unhide Text (VB 6.3)

    Here's a copy. Any help is appreciated. The dumb thing is I had it working, except the non-printing characters stayed on. I though there was a way to work around that, but maybe you have a better solution than hidden text?!
    egghead

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word Form Unhide Text (VB 6.3)

    The problem is that your dropdown list contains the value "Lease", but you test for "lease". Unless you tell VBA explicitly to do otherwise, text comparisons are case sensitive. If you use

    If ActiveDocument.FormFields("dropdown2").Result = "Lease" Then

    the code should do what you want.

    Note: whether non-printing characters are displayed or not is independent of this macro.

  13. #13
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Form Unhide Text (VB 6.3)

    That's why I made it a habit of always using UCase in those comparisons, to make this work regardless of the used case:

    If UCase(ActiveDocument.FormFields("dropdown2").Resul t) = "LEASE" Then

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •