Consulting

Results 1 to 8 of 8

Thread: Solved: Populating Text Field Forms from a UserForm (Correct Query)

  1. #1
    VBAX Regular
    Joined
    Jul 2008
    Location
    Adelaide
    Posts
    24
    Location

    Solved: Populating Text Field Forms from a UserForm (Correct Query)

    Hi
    I've created a UserForm that will assist the User to populate a set of fields within a Template each time it is opened. All the code works except for the cmdOkay_Click(), which returns an run-time error of 6028, 'The range cannot be deleted'. I'm not sure where I'm going wrong and looking for any help...

    [VBA]
    Private Sub cmdOkay_Click()
    Application.ScreenUpdating = False
    With ActiveDocument
    .Bookmarks("LetterDate").Range.Text = LetterDateText.Value
    .Bookmarks("ActivityItem").Range.Text = ActivityItemText.Value
    .Bookmarks("Addressee").Range.Text = AddresseeText.Value
    .Bookmarks("AddLine1").Range.Text = AddLine1Text.Value
    .Bookmarks("AddLine2").Range.Text = AddLine2Text.Value
    .Bookmarks("AddLine3").Range.Text = AddLine3Text.Value
    .Bookmarks("TitleSurname").Range.Text = TitleSurnameText.Value
    .Bookmarks("ComplaintDate").Range.Text = ComplaintDateText.Value
    .Bookmarks("EntityIssue").Range.Text = EntityIssueText.Value
    .Bookmarks("TeamLeader").Range.Text = TeamLeaderText.Value
    End With
    Application.ScreenUpdating = True
    Unload Me
    End Sub
    [/VBA]
    Last edited by arcanedevice; 09-02-2008 at 04:14 PM.

  2. #2
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Please don't delete your posts. A simple followup post would have been adequate.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Regular
    Joined
    Jul 2008
    Location
    Adelaide
    Posts
    24
    Location
    Hi
    I have restored the correct code above, although the run-time error was because I hadn't protected the document. However, now I'm getting run-time 4065. I thought the code I had was sufficient?
    Last edited by arcanedevice; 09-02-2008 at 04:23 PM.

  4. #4
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi arcanedevice,

    Try something based on:
    ActiveDocument.FormFields(YourName).Result = YourValue
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Regular
    Joined
    Jul 2008
    Location
    Adelaide
    Posts
    24
    Location
    Cheers, that worked well.

  6. #6
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Glad you got this sorted.....seems you were using formfields instead of bookmarks.

    Please mark your thread solved using the thread tools at the top of the page if this has fixed your problem.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi lucas,

    In most cases, formfields produce bookmarks with the same 'name' as the bookmark. The OP's references to fields and 'The range cannot be deleted' error message were the giveaway.

    FWIW, you can update formfields by referencing their bookmarks, but that requires unprotecting then reprotecting the document.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #8
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I knew that mcacropod. I should learn not to get involved before I've had a couple of cups of coffee. Word is different for me as Gerry has noted.

    Thanks for clarifying.
    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
  •