Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Mar 2006
    Location
    United Kingdom
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Storing field results (2003 11.65 SP2)

    Hello there. Could someone tell me how to store the result of the protected (for forms) field code? In particular, the document has the field: CreateDate, with a field/format property set to ddMMyy-HHmm. The value of the field will changa every time a new document based on the template is created.

    Although the document will be protected for forms (and indeed does have some form fields in it), this particular field this isn't a form field, so "ActiveDocument.Fields("NoteNo").Result" , obviously won't work.

    Any ideas will be apppreciated.

    Journey (new member)

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

    Re: Storing field results (2003 11.65 SP2)

    Welcome to Woody's Lounge!

    Do you want to store the create date in a variable? You don't need to look at a CreateDate field for that. It can be done as follows:

    Dim dtmCreated As Date
    dtmCreated = ActiveDocument.BuiltInDocumentProperties(wdPropert yTimeCreated)

    This takes the built-in document property and assigns it to the variable dtmCreated.

  3. #3
    New Lounger
    Join Date
    Mar 2006
    Location
    United Kingdom
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing field results (2003 11.65 SP2)

    Thank you, Hans. Doing it your way, can that info be added to the document? Also, the format needs to be stored/displayed as "ddMMyy-HHmm".

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

    Re: Storing field results (2003 11.65 SP2)

    I apparently misunderstood your question, sorry about that. It is not clear to me what you want - if you put a CreateDate field in a template, it will be set automatically each time a new document is created from the template, so there is no need for you to set it. You can specify the format as follows:
    - Unprotect the template.
    - Right-click the CreateDate field.
    - Select Toggle Field Codes from the popup menu.
    - You'll see something like { CREATEDATE @ "dd/MM/yyyy HH:mm:ss" }
    - Change the format string to "ddmmyy-HHmm"
    - Press F9 to hide the field code and update the field.
    - Re-protect the template for forms.
    - Save the template.

  5. #5
    New Lounger
    Join Date
    Mar 2006
    Location
    United Kingdom
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing field results (2003 11.65 SP2)

    Hans, I've already created the field - it is an integral part of the template, which will be used to create a unique document number.

    What I'd like to do is to get the value of that field and store it for use with the file name.

    So far, this is what I've got (in English)

    1) Change the directory to the place where the new document will be stored.
    2) Get the date/time field result and store it to a variable called mName1
    2) Get the result of the form field called Supplier and store it to a variable called mName2
    3) When the user goes to save the file, the default file name in the File Save As dialog box will show the values of mName 1 + mName2, i.e. 140205-1242

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

    Re: Storing field results (2003 11.65 SP2)

    Try

    mName1 = Format(ActiveDocument.BuiltInDocumentProperties(wd PropertyTimeCreated), "ddMMyy-HHmm")

    Note: setting the document title using the code you have will work, but when you save the document, the proposed name will be truncated at the hyphen. See How to set the default suggested filename to be displayed by the Save As dialog the first time a user saves a new document for more details.

  7. #7
    New Lounger
    Join Date
    Mar 2006
    Location
    United Kingdom
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing field results (2003 11.65 SP2)

    Your suggestion works great - thank you, Hans!!! I see what you mean about truncating the string. I'll have a think about the suggestions at the MVP site and go on from there.

    All the best!

Posting Permissions

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