PDA

View Full Version : Solved: Userform Problem in Word



Dragon71
03-19-2009, 10:00 PM
Guys

Got my userform to work the other day with help from Lucas (thanks again)
Trouble is i have created another userform identical to the first with just the arrays changed and i keep getting an error message
Runtime error 5012 You entered multiple destinations for a page,line,footnote ,endnote or comment
Please help


Code is below

Private Sub UserForm_Click()
End Sub

Private Sub UserForm_Initialize()
ListBox1.List = Array("Natural", "FRAS", "Ceramic", "Polyuethane")
ListBox1.ListIndex = 0
ListBox3.List = Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20")
ListBox3.ListIndex = 0
ListBox4.List = Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20")
ListBox4.ListIndex = 0
ListBox5.List = Array("Yes", "No")
ListBox5.ListIndex = 0
ListBox6.List = Array("N/A", "Damaged", "Replace", "Re Use", "Requires Repair")
ListBox6.ListIndex = 0
ListBox7.List = Array("Yes", "No")
ListBox7.ListIndex = 0
ListBox8.List = Array("N/A", "Completely Worn", "Outer Edge Worn", "Centre Worn")
ListBox8.ListIndex = 0
End Sub

Private Sub cmdOK_Click()
Call FillABookmark("Laggingtype", "Listbox1.Value")
Call FillABookmark("LaggingDia", TextBox1.Value)
Call FillABookmark("Laggingthicknessmax", ListBox3.Value)
Call FillABookmark("Laggingthicknessmin", ListBox4.Value)
Call FillABookmark("Laggingdamage", ListBox5.Value)
Call FillABookmark("Laggingdamagedetails", ListBox6.Value)
Call FillABookmark("Laggingwear", ListBox7.Value)
Call FillABookmark("Lagginweardetails", ListBox8.Value)
Call FillABookmark("LaggingTir", TextBox2.Value)
Call FillABookmark("Laggingpattern", TextBox4.Value)
End Sub

Private Sub cmdClearForm_Click()
Call FillABookmark("Laggingtype", "")
Call FillABookmark("LaggingDia", "")
Call FillABookmark("Laggingthicknessmax", "")
Call FillABookmark("Laggingthicknessmin", "")
Call FillABookmark("Laggingdamage", "")
Call FillABookmark("Laggingdamagedetails", "")
Call FillABookmark("Laggingwear", "")
Call FillABookmark("Laggingweardetails", "")
Call FillABookmark("LaggingTir", "")
Call FillABookmark("Laggingpattern", "")

End Sub

Private Sub cmdEnd_Click()
End
End Sub

Private Sub CommandButton1_Click()
Shell ("osk")
End Sub

Module i am using for both forms is

Sub FillABookmark(strBM_Name As String, strBM_Text As String)
With Selection
.GoTo what:=wdGoToBookmark, Name:=strBM_Name
.Collapse Direction:=wdCollapseEnd
ActiveDocument.Bookmarks(strBM_Name).Range.Text = strBM_Text
.MoveEnd unit:=wdCharacter, Count:=Len(strBM_Text)
ActiveDocument.Bookmarks.Add Name:=strBM_Name, Range:=Selection.Range
.Collapse Direction:=wdCollapseEnd
End With
End Sub


Form one is identical as said,just changes to the arrays
When you go to run it it gets that error

Thanks

Nelviticus
03-20-2009, 04:57 AM
Try replacing your FillABookmark sub with this:
Public Sub FillABookmark(strBM_Name As String, strBM_Text As String)

Dim rngBmk As Range

With ActiveDocument

If .Bookmarks.Exists(strBM_Name) Then

Set rngBmk = .Bookmarks(strBM_Name).Range
rngBmk.Text = strBM_Text
.Bookmarks.Add Name:=strBM_Name, Range:=rngBmk

End If

End With

End Sub
Regards

Dragon71
03-22-2009, 06:44 PM
Does not seem to work??:help
Enters details of first item as "Listbox1" and thats it no other items

Do i use this code to replace the exisiting,and will this run any futher user forms i have to create on this sheet??
What i am doing is creating some userforms to fill out certains sections of the sheet from lists etc,so i need something that will work right across all the forms
I am just copying the code from first form and modifying to suit new form layout

lucas
03-22-2009, 06:56 PM
Is your fillabookmark sub in a standard module?

Dragon71
03-22-2009, 07:18 PM
As far as i can gather
Just created a module and put the code in there??


Am i doing it wrong?

lucas
03-22-2009, 09:10 PM
More questions, what line of the code you posted above do you get the error on?

by the way, when posting code, select the code and hit the vba button to format it for the forum as nelvicus did.

Dragon71
03-22-2009, 09:23 PM
When i try it with the code you gave me previous the error i get is in the module
Line

.GoTo what:=wdGoToBookmark,Name:=strBM_Name



Sub FillABookmark(strBM_Name As String, strBM_Text As String)
With Selection
.GoTo what:=wdGoToBookmark, Name:=strBM_Name
.Collapse Direction:=wdCollapseEnd
ActiveDocument.Bookmarks(strBM_Name).Range.Text = strBM_Text
.MoveEnd unit:=wdCharacter, Count:=Len(strBM_Text)
ActiveDocument.Bookmarks.Add Name:=strBM_Name, Range:=Selection.Range
.Collapse Direction:=wdCollapseEnd
End With
End Sub

lucas
03-22-2009, 09:26 PM
Should you have parenthesis around the listbox1.value part? the other lines do not show that and the parentisis will cause it to just return a string ie listbox1.value
Private Sub cmdOK_Click()
Call FillABookmark("Laggingtype", "Listbox1.Value")

lucas
03-22-2009, 09:28 PM
Are you absolutely sure the bookmark exists? That is what nelviticus was doing, checking to see if the bookmark exists.

Dragon71
03-22-2009, 10:09 PM
Lucas

Bookmark exists and yes you were right on the parenthesis
Tried it and seems to be working ok with the code from Nelviticus in the module so will try it a bit more later and let you know how it goes
Thanks for the help guys..........appreciate it:bow: :bow: