PDA

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



arcanedevice
09-01-2008, 10:17 PM
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...


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

lucas
09-02-2008, 08:25 AM
Please don't delete your posts. A simple followup post would have been adequate.

arcanedevice
09-02-2008, 04:05 PM
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?

macropod
09-02-2008, 10:20 PM
Hi arcanedevice,

Try something based on:
ActiveDocument.FormFields(YourName).Result = YourValue

arcanedevice
09-03-2008, 03:20 AM
Cheers, that worked well.

lucas
09-03-2008, 06:27 AM
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.

macropod
09-03-2008, 06:37 AM
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.

lucas
09-03-2008, 06:45 AM
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.