S
SN
Hi, I was wondering if someone could please assist. With the below listed
code, i am providing users with a list box to select 20 items from that will
fill the assosciated bookmarked fields in word. I do however only have 20
bookmarked text from fields within my word document
I did indicated to users that they should only select twenty however, the
possiblities of a user selecting more is unstopable.
As soon as they select Done on the userform. My fields will be populated,
but if selected more than 20 an get the following error.
runtime error 5941 " The requested member of the collection does not exist.
I was hopeing that if a user receives this error instead of receiving the
above mentioned, They can get an error say, Please only select 20 items.
they can click okay and it will take them back to reselecting their items.
No my knowledge is limited with VBA and read up quite abit on Error
handeling but no idea how to implent it to correspond to my error.
I was hoping if anyone can maybe point me in a direction or any assistance
would be appreciated.
Thanks in Advance
SN
Code
Option Explicit
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim StrSkillList As String
Dim j As Long, k As Long
Dim var, var2, var3
Dim SkillsArray()
k = 1
For var = 1 To lstSkills.ListCount
If lstSkills.Selected(var - 1) = True Then
ReDim Preserve SkillsArray(j)
SkillsArray(j) = lstSkills.List(var - 1)
j = j + 1
End If
Next
For var2 = 0 To UBound(SkillsArray)
ActiveDocument.FormFields("Skill" & k).Result = _
SkillsArray(var2)
k = k + 1
Next
Unload Me
End Sub
Private Sub lstSkills_Click()
End Sub
Private Sub UserForm_Initialize()
Dim var
Dim myArray()
myArray = Array("Accountant", "Accounts Assistant", "AGS ", "Battle Area
Clearance Supervisor", "CAD Operator", "Dog Handler", "Driver Car", _
"Driver Heavy Goods", "Driver Other", "Driver Tracked", "EOD Ammo Tech",
"EOD Assault Pioneer", "EOD Banksman", _
"EOD Demolitions Safety Officer", "EOD Diver Commercial",etc etc etc etc )
For var = 0 To UBound(myArray)
lstSkills.AddItem myArray(var)
Next
lstSkills.ListIndex = 0
End Sub
code, i am providing users with a list box to select 20 items from that will
fill the assosciated bookmarked fields in word. I do however only have 20
bookmarked text from fields within my word document
I did indicated to users that they should only select twenty however, the
possiblities of a user selecting more is unstopable.
As soon as they select Done on the userform. My fields will be populated,
but if selected more than 20 an get the following error.
runtime error 5941 " The requested member of the collection does not exist.
I was hopeing that if a user receives this error instead of receiving the
above mentioned, They can get an error say, Please only select 20 items.
they can click okay and it will take them back to reselecting their items.
No my knowledge is limited with VBA and read up quite abit on Error
handeling but no idea how to implent it to correspond to my error.
I was hoping if anyone can maybe point me in a direction or any assistance
would be appreciated.
Thanks in Advance
SN
Code
Option Explicit
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim StrSkillList As String
Dim j As Long, k As Long
Dim var, var2, var3
Dim SkillsArray()
k = 1
For var = 1 To lstSkills.ListCount
If lstSkills.Selected(var - 1) = True Then
ReDim Preserve SkillsArray(j)
SkillsArray(j) = lstSkills.List(var - 1)
j = j + 1
End If
Next
For var2 = 0 To UBound(SkillsArray)
ActiveDocument.FormFields("Skill" & k).Result = _
SkillsArray(var2)
k = k + 1
Next
Unload Me
End Sub
Private Sub lstSkills_Click()
End Sub
Private Sub UserForm_Initialize()
Dim var
Dim myArray()
myArray = Array("Accountant", "Accounts Assistant", "AGS ", "Battle Area
Clearance Supervisor", "CAD Operator", "Dog Handler", "Driver Car", _
"Driver Heavy Goods", "Driver Other", "Driver Tracked", "EOD Ammo Tech",
"EOD Assault Pioneer", "EOD Banksman", _
"EOD Demolitions Safety Officer", "EOD Diver Commercial",etc etc etc etc )
For var = 0 To UBound(myArray)
lstSkills.AddItem myArray(var)
Next
lstSkills.ListIndex = 0
End Sub