UserForm Initialize not working

L

LEU

I have the following macro that wont fill in my form with the existing data
when I open it.

Private Sub UserForm_Initialize()

Dim myType1, myType2, myType3, myType4, myType5, _
myType6, myType7, myType8, myType9, myType10, _
myType11, myType12, myType13, myType14

myType1 = Split(" |D|N", "|")
With ComboBox1
.List = myType1
.ListIndex = 0
.MatchRequired = True
End With

myType2 = Split(" |D|N", "|")
With ComboBox2
.List = myType2
.ListIndex = 0
.MatchRequired = True
End With

myType3 = Split(" |D|N", "|")
With ComboBox3
.List = myType3
.ListIndex = 0
.MatchRequired = True
End With

myType4 = Split(" |D|N", "|")
With ComboBox4
.List = myType4
.ListIndex = 0
.MatchRequired = True
End With

myType5 = Split(" |D|N", "|")
With ComboBox5
.List = myType5
.ListIndex = 0
.MatchRequired = True
End With

myType6 = Split(" |D|N", "|")
With ComboBox6
.List = myType6
.ListIndex = 0
.MatchRequired = True
End With

myType7 = Split(" |D|N", "|")
With ComboBox7
.List = myType7
.ListIndex = 0
.MatchRequired = True
End With

myType8 = Split(" |D|N", "|")
With ComboBox8
.List = myType8
.ListIndex = 0
.MatchRequired = True
End With

myType9 = Split(" |D|N", "|")
With ComboBox9
.List = myType9
.ListIndex = 0
.MatchRequired = True
End With

myType10 = Split(" |D|N", "|")
With ComboBox10
.List = myType10
.ListIndex = 0
.MatchRequired = True
End With

myType11 = Split(" |D|N", "|")
With ComboBox11
.List = myType11
.ListIndex = 0
.MatchRequired = True
End With

myType12 = Split(" |D|N", "|")
With ComboBox12
.List = myType12
.ListIndex = 0
.MatchRequired = True
End With

myType13 = Split(" |D|N", "|")
With ComboBox13
.List = myType13
.ListIndex = 0
.MatchRequired = True
End With

myType14 = Split(" |D|N", "|")
With ComboBox14
.List = myType14
.ListIndex = 0
.MatchRequired = True
End With

On Error Resume Next
Dim oBMs As Bookmarks
TextBox1.Value = oBMs("bkHWS1").Range.Text
TextBox2.Value = oBMs("bkHWS2").Range.Text
TextBox3.Value = oBMs("bkHWS3").Range.Text
TextBox4.Value = oBMs("bkHWS4").Range.Text
TextBox5.Value = oBMs("bkHWS5").Range.Text
TextBox6.Value = oBMs("bkHWS").Range.Text
TextBox7.Value = oBMs("bkHWS7").Range.Text
TextBox8.Value = oBMs("bkHWS8").Range.Text
TextBox9.Value = oBMs("bkHWS9").Range.Text
TextBox10.Value = oBMs("bkHWS10").Range.Text
TextBox11.Value = oBMs("bkHWS11").Range.Text
TextBox12.Value = oBMs("bkHWS12").Range.Text
TextBox13.Value = oBMs("bkHWS13").Range.Text
TextBox14.Value = oBMs("bkHWS14").Range.Text

ComboBox1.Value = oBMs("ShiftDay1").Range.Text
ComboBox2.Value = oBMs("ShiftDay2").Range.Text
ComboBox3.Value = oBMs("ShiftDay3").Range.Text
ComboBox4.Value = oBMs("ShiftDay4").Range.Text
ComboBox5.Value = oBMs("ShiftDay5").Range.Text
ComboBox6.Value = oBMs("ShiftDay6").Range.Text
ComboBox7.Value = oBMs("ShiftDay7").Range.Text
ComboBox8.Value = oBMs("ShiftDay8").Range.Text
ComboBox9.Value = oBMs("ShiftDay9").Range.Text
ComboBox10.Value = oBMs("ShiftDay10").Range.Text
ComboBox11.Value = oBMs("ShiftDay11").Range.Text
ComboBox12.Value = oBMs("ShiftDay12").Range.Text
ComboBox13.Value = oBMs("ShiftDay13").Range.Text
ComboBox14.Value = oBMs("ShiftDay14").Range.Text

End Sub
 
D

Doug Robbins - Word MVP

You code has no idea where the oBMs are.

Use

With ActiveDocument
TextBox1.Text = .Bookmarks("bkHWS1").Range.Text
TextBox2.Text = .Bookmarks("bkHWS2").Range.Text
TextBox3.Text = .Bookmarks("bkHWS3").Range.Text
TextBox4.Text = .Bookmarks("bkHWS4").Range.Text
TextBox5.Text = .Bookmarks("bkHWS5").Range.Text
TextBox6.Text = .Bookmarks("bkHWS").Range.Text
TextBox7.Text = .Bookmarks("bkHWS7").Range.Text
TextBox8.Text = .Bookmarks("bkHWS8").Range.Text
TextBox9.Text = .Bookmarks("bkHWS9").Range.Text
TextBox10.Text = .Bookmarks("bkHWS10").Range.Text
TextBox11.Text = .Bookmarks("bkHWS11").Range.Text
TextBox12.Text = .Bookmarks("bkHWS12").Range.Text
TextBox13.Text = .Bookmarks("bkHWS13").Range.Text
TextBox14.Text = .Bookmarks("bkHWS14").Range.Text
ComboBox1.Text = .Bookmarks("ShiftDay1").Range.Text
ComboBox2.Text = .Bookmarks("ShiftDay2").Range.Text
ComboBox3.Text = .Bookmarks("ShiftDay3").Range.Text
ComboBox4.Text = .Bookmarks("ShiftDay4").Range.Text
ComboBox5.Text = .Bookmarks("ShiftDay5").Range.Text
ComboBox6.Text = .Bookmarks("ShiftDay6").Range.Text
ComboBox7.Text = .Bookmarks("ShiftDay7").Range.Text
ComboBox8.Text = .Bookmarks("ShiftDay8").Range.Text
ComboBox9.Text = .Bookmarks("ShiftDay9").Range.Text
ComboBox10.Text = .Bookmarks("ShiftDay10").Range.Text
ComboBox11.Text = .Bookmarks("ShiftDay11").Range.Text
ComboBox12.Text = .Bookmarks("ShiftDay12").Range.Text
ComboBox13.Text = .Bookmarks("ShiftDay13").Range.Text
ComboBox14.Text = .Bookmarks("ShiftDay14").Range.Text
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
L

LEU

Thanks Doug. I know I was missing something simple.

I have a different question. If I have a userform with 3 test boxes and I
want to add the value of textbox1 and textbox2, then put that number in
textbox3. How do I do that?

Example:

TextBox1 = 10
TextBox2 = 5
then
TextBox3 = 15

LEU
 
D

Doug Robbins - Word MVP

TextBox3.Text = TextBox1.Text + TextBox2.Text

or

TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)

or

If IsNumeric(TextBox1.Text) Then
If IsNumeric(TextBox2.Text) Then
TextBox3.Text = TextBox1.Text + TextBox2.Text
Else
MsgBox "TextBox2 does not contain a numeric entry."
End if
Else
MsgBox "TextBox1 does not contain a numeric entry."
End if


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top