Results 1 to 9 of 9
  1. #1
    Lounger
    Join Date
    Oct 2003
    Location
    Calgary, Alberta, Canada
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert text after bookmark (Word 2000)

    I'm trying to insert information into a document using UserForms. I want the information from the textbox to fill in the blank - that's easy. It's the part where I say if the textbox is empty, insert "Not applicable". The code is as follows.

    Set rng = ActiveDocument.Bookmarks("electric").Range
    If txtschedule.Value = "" Then
    ' insert not applicable here
    Else
    rng.InsertAfter txtElectric
    End If

    I've tried a number of variations - none of which seem to be working. Any help would be appreciated.

    Thanks
    Mary

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

    Re: Insert text after bookmark (Word 2000)

    Does this do what you want?
    <code>
    Set rng = ActiveDocument.Bookmarks("electric").Range
    If txtSchedule = "" Then
    rng.InsertAfter "Not Applicable"
    Else
    rng.InsertAfter txtElectric
    End If
    </code>
    If not, can you tell us what the problem is? Do you get an error message, or is the result unexpected, or is there no result at all?

  3. #3
    Lounger
    Join Date
    Oct 2003
    Location
    Calgary, Alberta, Canada
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert text after bookmark (Word 2000)

    I actually tried that. Nothing happens. The bookmark is there but there's no text behind it. The information from the text boxes fills in but if the text box is blank, then I get nothing in the document.

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

    Re: Insert text after bookmark (Word 2000)

    That's strange - it worked in a quick example I set up. Could you attach your document, with sensitive information removed or replaced with dummy data?

  5. #5
    Lounger
    Join Date
    Oct 2003
    Location
    Calgary, Alberta, Canada
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert text after bookmark (Word 2000)

    I'd love to attach the document however it doesn't want to go. I keep getting the notice that the file is too big - it's only 147 kb. I've checked the cookies and that doesn't appear to be the problem.

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

    Re: Insert text after bookmark (Word 2000)

    There is a maximum size of 100 KB for attachments. Try creating a zip file from the document and attaching that.

  7. #7
    Lounger
    Join Date
    Oct 2003
    Location
    Calgary, Alberta, Canada
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert text after bookmark (Word 2000)

    Trying yet again.

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

    Re: Insert text after bookmark (Word 2000)

    I get an error message when I click OK in one of the other forms that the bookmark "renovate" doesn't exist. Apart from that, the code works OK: if I leave the txtschedule text box on frmSchedule blank, the appropriate N/A and Not Applicable texts are inserted. See screenshot. Perhaps you intended

    If txtElectric = "" Then
    rng.InsertAfter "Not Applicable"
    Else
    rng.InsertAfter txtElectric
    End If

    instead of

    If txtschedule = "" Then
    rng.InsertAfter "Not Applicable"
    Else
    rng.InsertAfter txtElectric
    End If

  9. #9
    Lounger
    Join Date
    Oct 2003
    Location
    Calgary, Alberta, Canada
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert text after bookmark (Word 2000)

    See what happens when you stare at something for hours on end ... you miss the most obvious problem. I was starting to question my sanity - although it's probably much too late for that.

    It's working properly now.

    Thank you very much.

Posting Permissions

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