Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wrong field being selected (English/Word 2000/SR-3

    I have a letter template with the following fields:
    { DATE @ "MMMM d, yyyy" }
    { info title "{ DATE @ "yyyyMMdd" }" }{MACROBUTTON NoMacro [Click here and type recipient

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Wrong field being selected (English/Word 2000/SR-3

    Phil,

    I created a document containing exactly the fields you show, and ran your Macro. It did what you expect. This was running Office 2003 SP1.

    I didn't run the Macro as an Autonew, do you get the same problem if you single step the Macro interactively?

    StuartR

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wrong field being selected (English/Word 2000/SR-3

    Hi Stuart:
    When I run the macro in the template, one step at a time, it works. I can't understand why it won't work as an AutoNew macro. It selects the formtext field. I even tried selecting a field by using

    Which:wdGoToAbsolute, Count:=X

    & tried X =-1, 0, 1, 2..., but nothing worked.

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Wrong field being selected (English/Word 2000/SR-3

    Strange, I just saved it as a template and tested the AutoNew function. It works correctly on my Windows XP SP2, Office 2003 SP1 system.

    StuartR

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Wrong field being selected (English/Word 2000/SR-3

    It looks to me like the <code>Selection.NextField.Select</code> was executing after the AutoNew macro completed. This would certainly account for the behaviour you described.

    How about putting a bookmark around the Date field, you could then use something like...
    <code>Activedocument.Bookmarks("bmkDate").Range.Fi elds(1).Locked = True</code>
    to lock it without changing the selection.

    Alternatively, if you know that the Date field is the 3rd field in the document you could just use
    <code>Activedocument.Fields(3).Locked = True</code>
    but this might take more maintenance in the long term

    StuartR

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wrong field being selected (English/Word 2000/SR-3

    Hi Stuart:
    Thanks again for all the help. I changed the the AutoNew macro to this:<pre>Public Sub AutoNew()
    ActiveDocument.Fields(2).Update
    ActiveDocument.Fields(2).Delete
    Selection.GoTo What:=wdGoToField, Name:="Date"
    Selection.Expand
    ActiveDocument.Fields.Locked = True
    Selection.GoTo What:=wdGoToField, Name:="macrobutton"
    Selection.Expand
    End Sub</pre>


    It seems to work OK. Do you see any maintenance problems with it?

  7. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Wrong field being selected (English/Word 2000/SR-3

    Hi Phil,

    If you've only got one macrobutton field, you could also use:
    For i = 1 To ActiveDocument.Fields.Count
    If ActiveDocument.Fields(i).Type = wdFieldMacroButton Then
    ActiveDocument.Fields(i).Select
    End If
    Next

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  8. #8
    New Lounger
    Join Date
    Oct 2004
    Location
    Sydney, New South Wales, Australia
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wrong field being selected (English/Word 2000/SR-3

    some fileds also allow you to add a bookmark such as the Checkbox.

    So maybe add a bookmark to the field control and then refer to the bookmark name.

    Pete

  9. #9
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Wrong field being selected (English/Word 2000/SR-3

    Phil,

    It took me a few moments to understand why you were updating ActiveDocument.Fields(2) and then immediately deleting it. Very cute.

    Why are you using the selection object to get to the Date field, you could just lock the field by number or bookmark.
    <code> ActiveDocument.Fields(5).Lock </code>
    or
    <code> ActiveDocument.Bookmarks("DateField").Fields.Lock </code>

    The selection of the MacroButton seems OK, but would lead to maintenance problems if you ever added a second MacroButton to this document, you could bookmark that field as well and use
    <code> ActiveDocument.Bookmarks("StartPoint").Range.Selec t</code>

    StuartR

  10. #10
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wrong field being selected (English/Word 2000/

    Thanks to everyone for their suggestions. I've been a little reluctant to bookmark the fields because I have View/Bookmarks checked & didn't want to see it in the letter. But I will try locking the fields by number. I think I'll also experiment & use a hidden bookmark. I remember that macropod came up with a way to create a hidden bookmark by using a SET field & starting the bookmark name with an underscore. I'll test both these ideas out.
    Thanks again,

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wrong field being selected (English/Word 2000/

    Hi Stuart:
    Sorry for the delay, but I was away from the computer. I found the problem, but don't really understand it & can't seem to correct it. I was creating a new document based on my letter template by running the following macro:
    <pre>Sub Letter()
    '
    ' Letter Macro
    ' Creates a personal letter & locks date field 5/28/00
    '
    Documents.Add Template:= _
    "C:WINDOWSApplication DataMicrosoftTemplatesLettersLetter.dot", _
    NewTemplate:=False, DocumentType:=0
    ' Selection.NextField.Select
    ' Selection.Fields.Locked = True
    ' Selection.NextField.Select
    End Sub</pre>

    The lines that I commented out were causing the problem. I had those lines so that I could get the current date & then lock it.

    But now I have a new problem. When I create a letter based on that template, the date field is locked (which I want), but doesn't update. So now I need something in my letter template that will select the date field & lock it. The macro that I use to create my letter is in a global template. Does that run before the AutoNew macro runs or after?

    Thanks, Stuart. I appreciate it.

  12. #12
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Wrong field being selected (English/Word 2000/

    Phil,

    I know how you feel about bookmarks - but since these are going to be in your template for use by AutoNew you could delete them as soon as they have been used.

    StuartR

  13. #13
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wrong field being selected (English/Word 2000/

    Hi Stuart:
    That's a great idea! However, there is still something wrong with my syntax because I'm getting a compile error (Data or method not found with
    ActiveDocument.Bookmarks("InfoField").Fields.Locke d = True
    I'm using Word 2000, so it might need something slightly different. I can't use Fields.Lock; I must use Fields.Locked = True. But even that can't be used after the bookmark. Here's what I tried:
    <pre>Public Sub AutoNew()
    Application.ScreenUpdating = False
    ActiveDocument.Bookmarks("InfoField").Fields.Locke d = True
    ActiveDocument.Fields("Info").Delete
    ActiveDocument.Bookmarks("Date").Fields.Lock
    ActiveDocument.Bookmarks("Date").Delete
    ActiveDocument.Bookmarks("StartPoint").Range.Selec t
    ActiveDocument.Bookmarks("StartPoint").Delete
    Application.ScreenUpdating = True
    End Sub</pre>


  14. #14
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Wrong field being selected (English/Word 2000/

    ActiveDocument.Bookmarks("InfoField").range.Fields.Locked = True

    StuartR

  15. #15
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wrong field being selected (English/Word 2000/

    Thanks, Stuart. Now I get an error message on the next line:

    ActiveDocument.Fields("Info").Delete

    I know I can do it by number: "ActiveDocument.Fields(2).Delete", but I thought you could do it by name?

Page 1 of 2 12 LastLast

Posting Permissions

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