Consulting

Results 1 to 12 of 12

Thread: Solved: How do I clear or overwrite a bookmark?

  1. #1

    Solved: How do I clear or overwrite a bookmark?

    In continuation with my earlier problem with alot of help from gibbo1715 we came up with this macro to copy the formfield into a bookmark. The net result ends with the bookmark concatinating with the text from the form field.

    My question is, how do i clear the bookmark before i copy the formfield or how do i overwrite the bookmark?


    [vba]
    Public Sub Copy1()
    Dim string1 As String
    string1 = ActiveDocument.FormFields("Description2").Result
    ActiveDocument.Unprotect
    ActiveDocument.Bookmarks("position2").Range = string1
    ActiveDocument.Protect Password:="", noreset:=True, Type:=wdAllowOnlyFormFields
    End Sub
    [/vba]

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    All I can see in your earlier thread is a reply by fumei indicating that you should probably use REF fields which, from what I can see, would be the thing to do. Cam you give more details or post a sample doc or something to help us understand more what it is you are trying to achieve?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3

    Attached file hopefully (zipped)

    Thanks Tony,

    What I would like to do is protect the document so that only the first page is used for data entry The data entered into first page (Customer Copy) is then copied onto the following 2 sheets (Marlin Copy & Return Copy).

    The attached file has just the first cell set up. concurrent exits from the cell results in multiple copies of data in the reciprocating cells on the other 2 sheets.

    I hope that explains it better? (embarrassed silence)

  4. #4
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Dave

    This will do what your after

    Gibbo

    [VBA]Dim string1 As String
    Public Sub Copy1()
    string1 = ActiveDocument.FormFields("Text1").Result
    ActiveDocument.Unprotect

    Call UpdateBookmark

    ActiveDocument.Protect Password:="", noreset:=True, Type:=wdAllowOnlyFormFields
    End Sub
    Sub UpdateBookmark()
    Dim BMRange As Range
    Set BMRange = ActiveDocument.Bookmarks("Text2").Range
    BMRange.Text = string1
    ActiveDocument.Bookmarks.Add "Text2", BMRange
    End Sub

    [/VBA]

  5. #5
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    You don't need code for this at all.

    Sticking with your CustName sample, set the Text Field on Page 1 to "Calculate On Exit" and remove the Exit macro. Where you want it on Page 2, get rid of the bookmark, press Ctrl+F9 to insert a field and then (inside the braces) type REF CustName (or just CustName). That's it. Do the same thing with all your other fields.

    I think that's more or less what Gerry (fumei) said when you first posted.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #6

    solved


    Tony

    That works amazingly well, I was so dense I didn't realise what Gerry was trying to tell me (I thought that I needed to use an ASK field with a REF) So... sorry Gerry, kudos to you for realising what I wanted even though I didn't explain myself at all well.

    Paul great fix for the problem I posed, but its probably neater using the REF method

  7. #7
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Glad you've got it working
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Not being a Wordie as Gerry will attest I have a hard time using the native user data input tools that come with Word...such as those from the forms toolbar. They seem much less intuitive than using a userform and bookmarks.

    Can you guys...Gerry, Tony..tell me if there is an unrealized advantage to using the input tools from the forms toolbar as opposed to using a userform?

    It seems like I have more control over the appearance of the document after users add data using a userform....often if I try to use fields in the documnet the data often gets disorganized(for lack of a better word) by the users.

    If I use a userform the data goes exactly where I want it and it is done...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  9. #9
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    You do have more control with a UserForm and VBA. But Word Forms have a potential big advantage in that they can run without code - many installations are happier with that, especially if documents are arriving via e-mail. Word Forms also let the user see what is being produced and how their input fits into the document - and the document may contain other help for them that may be far too voluminous to fit easily on a UserForm. As far as layout changing - using fixed size table cells is a good way to control that. All that said, Forms controls are very limited and there are things you can't do with them - it's horses for courses.

    ActiveX controls (from the Control Toolbox) I prefer to avoid - they don't always work well with Word and, again, they can trigger macro warnings.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  10. #10
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Thanks Tony...that clears up much for me.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  11. #11
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    This is a design and security issue, and I agree with Tony.

    Where I am working within our in-house environment, so I know what the security levels are, generally speaking (for documents that I am the owner of) I tend to use userforms. I prefer being able to design it exactly the way I want, and I can preform all error trapping within that context.

    When everything is correct, THEN I fill the document with the user input.

    When documents are going out to people that I have no direct linkage with, and can therefore not give support fully, I use formfields.

    Where users are of limited experience, I use formfields, for precisely the reason Tony mentions. The users can see things "live' so to speak. Formfields themselves have Help messages that can be accessed, which can be a great advantage. Plus, (with not using OnEntry/OnExit macros the exception), as Tony mentions, they do not require code. That may be a significant factor.

    I like userforms, and use them a lot. However, the bottom line is that as a developer you bring a solution that is appropriate for the circumstance. You have to remain flexible and design something that fits the requirements.

    Sometimes userforms really are the best way to go, sometimes not.

    BTW: re: a thread by SOS here. We continued some discussion privately, and he sent me his final product. One of the most complex and well designed userforms I have seen. Very slick and thoughtfully designed. From context sensitive labels that gave information on whatever the user was doing, to context sensitive Visible/Not Visible controls depending on what the user was doing. Rather impressive. It was a prime example where the complexities were properly handled by a userform. Trying to do it with formfields, and other fields in the template would have been a nightmare.

    Some of it could be done better - and that is always the case for anyone. Me too. OK, maybe not Tony, but he is an exception.

    But it was an excellent example of someone actually thinking...what do I REALLY need? Thinking...what a concept.

    I am going to use his userform as an example in my Word VBA course. Deconstructing it will be an good teaching example.

  12. #12
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Thanks Gerry..Tony. Good insights for infrequent users of Word.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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