Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New Lounger
    Join Date
    May 2004
    Location
    Santa Barbara, California, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Address into Form Field (Word 2003)

    Is there a way to insert an address from Outlook into a Word, Protected Form.

    Word 2003 doesn't seem to allow a macro to insert data into a protected form field.

    Thanks,
    John

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

    Re: Address into Form Field (Word 2003)

    Hi John:
    You would need on OnEntry (or OnExit, depending on your needs) macro that would unprotect the document, insert the text, & then reprotect the document without resetting the form fields. The latter is accomplished with the line:<pre>.noreset = True</pre>

    Hope this helps,

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

    Re: Address into Form Field (Word 2003)

    Hi Phil,

    Why is it necessary to unprotect the form if you want to programmatically insert data into a FormField (as John indicates he wants to do)? ActiveDocument.FormFields("Name") = "Value" works fine for me in Word 2003 without unprotecting the doc.

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

    Re: Address into Form Field (Word 2003)

    Hi Jan:
    You're right. I think it's a case of my fingers typing before I finish reading the question. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> Since all he's doing is inserting text into the form field itself, it wouldn't be necessary to unprotect the document. I guess I was thinking of all the limitations that a protected document has & that you needed to unprotect it to use other features.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Address into Form Field (Word 2003)

    In Word 2002, I get an error unless I specify the Result property:

    ActiveDocument.FormFields("Name").Result = "Value"

    (In Word 2002, the default property, according to the Object Browser, is .Type

  6. #6
    New Lounger
    Join Date
    May 2004
    Location
    Santa Barbara, California, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Address into Form Field (Word 2003)

    Hi All. Thanks for the responses.

    I am not a VBA programmer, however. Just a guy trying to get a problem solved that it seems Microsoft would want to make an easier solution for. This has been a struggle for too many releases...

    If someone would be willing to tweak the following to add the necessary code, for Word 2003, I sure would appreciate it:

    Thanks,

    John
    ______________

    Public Sub InsertAddressFromOutlook()
    Dim strCode, strAddress As String
    Dim iDoubleCR As Integer

    'Set up the formatting codes in strCode
    strCode = "<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr
    strCode = strCode & "<PR_COMPANY_NAME>" & vbCr
    strCode = strCode & "<PR_POSTAL_ADDRESS>" & vbCr

    'Let the user choose the name in Outlook
    strAddress = Application.GetAddress("", strCode, False, 1, , , True, True)

    'Eliminate blank lines by looking for two carriage returns in a row
    iDoubleCR = InStr(strAddress, vbCr & vbCr)
    While iDoubleCR <> 0
    strAddress = Left(strAddress, iDoubleCR - 1) & Mid(strAddress, iDoubleCR + 1)
    iDoubleCR = InStr(strAddress, vbCr & vbCr)
    Wend

    'Insert the modified address at the current insertion point
    Selection.TypeText strAddress
    End Sub

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Address into Form Field (Word 2003)

    <P ID="edit" class=small>(Edited by jscher2000 on 16-May-04 19:09. )</P>Does it not work in Word 2003? If not, do you get an error message?

    Second, part of this code can be made more efficient starting with Word 2000 (VBA 6.0+):

    <UL>'Eliminate blank lines by looking for two carriage returns in a row
    iDoubleCR = InStr(strAddress, vbCr & vbCr)
    While iDoubleCR <> 0
    strAddress = Left(strAddress, iDoubleCR - 1) & Mid(strAddress, iDoubleCR + 1)
    iDoubleCR = InStr(strAddress, vbCr & vbCr)
    Wend[/list]now can be written as

    <UL>'Eliminate blank lines by looking for two carriage returns in a row
    strAddress = Replace(strAddress, vbCr & vbCr, vbCr)[/list]Lazily, I didn't actually test this, but it should work in theory. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Added: Oh, duh, the last statement needs to be changed:

    <UL>Selection.TypeText strAddress[/list]will need to be changed to the code from the above posts to assign the result to the textbox. Note that the name of the textbox is the one you assigned in the form field's properties dialog (as its "bookmark").

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

    Re: Address into Form Field (Word 2003)

    <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    You're right of course... Sorry for my typo!

  9. #9
    New Lounger
    Join Date
    May 2004
    Location
    Santa Barbara, California, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Address into Form Field (Word 2003)

    Here's my effort, below.

    Got the following error in Word 2003: Run Time Error '5981': Could not open macro storage.

    Again -not a programmer so may not be interpretting instructions correctly.

    Thanks for any help, John
    ____________________________

    Public Sub InsertAddressFromOutlook()
    Dim strCode, strAddress As String
    Dim iDoubleCR As Integer

    'Set up the formatting codes in strCode
    strCode = "<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr
    strCode = strCode & "<PR_COMPANY_NAME>" & vbCr
    strCode = strCode & "<PR_POSTAL_ADDRESS>" & vbCr

    'Let the user choose the name in Outlook
    strAddress = Application.GetAddress("", strCode, False, 1, , , True, True)

    'Eliminate blank lines by looking for two carriage returns in a row
    strAddress = Replace(strAddress, vbCr & vbCr, vbCr)

    'Insert the modified address at the current insertion point
    ActiveDocument.FormFields("formaddress").Result = "strAddress"

    End Sub

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Address into Form Field (Word 2003)

    On that last line, you'll want to take the " marks off of strAddress in order to get the contents of strAddress (otherwise you just get the literal text strAddress).

    That error message just doesn't make much sense in this context. Can you describe where you saved the macro? For example, is it in the protected document, in the template to which the protected document is attached, in Normal.dot, etc. I don't use Word 2003, so the security situation may have changed in a way that is affecting this macro. Hopefully a Word 2003 user can replicate your setup.

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

    Re: Address into Form Field (Word 2003)

    The error message is mentioned in MSKB article INFO: Corrupt Normal.dot Causes Errors When Automating Word in connection with a corrupt Normal.dot. See if the steps outlined there solve your problem.

  12. #12
    New Lounger
    Join Date
    May 2004
    Location
    Santa Barbara, California, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Address into Form Field (Word 2003)

    Took the quotes out. Same error persists.

    Macro is in Normal.dot, newmacros.

    Thanks

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Address into Form Field (Word 2003)

    I didn't visit the link HansV posted, but if you close Word and rename your Normal.dot template to something else (e.g., oldNormal.dot), you can use the Organizer (Tools>Macro>Macros>Organizer) to copy over AutoText entries, Styles, and Macros to the clean new Normal.dot that Word will create for you.

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

    Re: Address into Form Field (Word 2003)

    > Got the following error in Word 2003: Run Time Error '5981': Could not open macro storage.

    Another possible cause for this error is a name conflict. I encountered that once when I accidently gave a new macro the same name as an existing one in another code module. Probably not the case here, but you never know for sure until verified...

  15. #15
    New Lounger
    Join Date
    May 2004
    Location
    Santa Barbara, California, USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Address into Form Field (Word 2003)

    Can anyone try the code in Word 2003 and verify for me that it works?

    I renamed all Normal.dot and create a new one and put the macro in there. I also renamed the Macro
    Still get the error: "Run Time Error '5981', Could Not Open Macro Storage."

    I am trying to insert address into a text form field in a form protected document.
    __________
    Another issue, perhaps related?, when I open the document (which originated with a service company), I get the following:
    "Opening the document will run the following SQL command: Select * from K:etc.etc....
    Data from the database will be placed in your document. Do you wish to continue?" Yes / No.

    Can someone explain this to me and help me to get it to stop asking. Thanks.
    Thanks for the help,
    John

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
  •