S
Sesame
Hi
I currently have a Template with a textbox (tbName), a listbox (Listbox2)
and an "Add" button (cmdAddName). So user can type a name in the textbox,
click the Add command button, the name will appear in the listbox. This can
be done repeatitively so that eventually there's a list of Names. And this
list of names will be inserted as bookmarks in the document. But now, I need
it to store 2 Names at once. Ultimately, the user could enter 2 Names,
separated by a comma or a semi colon (1st is long name, 2nd is short name),
for e.g "Samantha, Sam" or "Samantha; Sam". Again, store them as list of
names (but bound with 2 items instead of 1), then insert the list as
bookmarks again, so that it looks like this in the document.
SAMANTHA ("SAM")
Any help would be very much appreciated. I'll paste the codes I have now.
Thank you!!
Private Sub cmdAddName_Click()
thisProcName = "Name List"
If Trim(tbName) <> "" Then
With ListBox2
.ListIndex = -1
On Error Resume Next
.Text = tbName.Text
On Error GoTo 0
If Not (.ListIndex >= 0) Then
ListBox2.AddItem tbName.Text
tbName.Text = ""
tbName.SetFocus
cmdAddName.Enabled = False
.TopIndex = .ListCount
Else
MsgBox "This name is already in the list.", vbOKOnly,
ModProcName
End If
End With
End If
End Sub
Private Sub ListBox2_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Dim thisItem As Integer
With ListBox2
thisItem = .ListIndex
If KeyCode = vbKeyDelete And thisItem <> -1 Then
.RemoveItem thisItem
If thisItem < .ListCount Then
'select the new item
If thisItem < .ListCount Then .Selected(thisItem) = True
End If
End If
End With
End Sub
Private Sub tbName_Change()
cmdAddName.Enabled = (Trim(tbName) <> "")
End Sub
I currently have a Template with a textbox (tbName), a listbox (Listbox2)
and an "Add" button (cmdAddName). So user can type a name in the textbox,
click the Add command button, the name will appear in the listbox. This can
be done repeatitively so that eventually there's a list of Names. And this
list of names will be inserted as bookmarks in the document. But now, I need
it to store 2 Names at once. Ultimately, the user could enter 2 Names,
separated by a comma or a semi colon (1st is long name, 2nd is short name),
for e.g "Samantha, Sam" or "Samantha; Sam". Again, store them as list of
names (but bound with 2 items instead of 1), then insert the list as
bookmarks again, so that it looks like this in the document.
SAMANTHA ("SAM")
Any help would be very much appreciated. I'll paste the codes I have now.
Thank you!!
Private Sub cmdAddName_Click()
thisProcName = "Name List"
If Trim(tbName) <> "" Then
With ListBox2
.ListIndex = -1
On Error Resume Next
.Text = tbName.Text
On Error GoTo 0
If Not (.ListIndex >= 0) Then
ListBox2.AddItem tbName.Text
tbName.Text = ""
tbName.SetFocus
cmdAddName.Enabled = False
.TopIndex = .ListCount
Else
MsgBox "This name is already in the list.", vbOKOnly,
ModProcName
End If
End With
End If
End Sub
Private Sub ListBox2_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Dim thisItem As Integer
With ListBox2
thisItem = .ListIndex
If KeyCode = vbKeyDelete And thisItem <> -1 Then
.RemoveItem thisItem
If thisItem < .ListCount Then
'select the new item
If thisItem < .ListCount Then .Selected(thisItem) = True
End If
End If
End With
End Sub
Private Sub tbName_Change()
cmdAddName.Enabled = (Trim(tbName) <> "")
End Sub