Only displaying first 8 characters of a field

J

Jean Pereira

Using Office 2003 and Windows XP

Have created a userform which users choose info from and which is then
placed in cells on a table.

I want to display only the first 8 characters of a combo box field which
contains a number followed by a description ( 12345678 - description) but
don't know how.

Thanks in advance for any help
 
G

Greg Maxey

Assuming that you have the number and decription displayed in the comboBox
e.g.,

Private Sub UserForm_Initialize()
With Me.ComboBox1
.AddItem "12345678 - This is a number"
.AddItem "23457689 - This is another number"
.AddItem "33333333 - As is this"
End With
End Sub

and you want only the first eight digits of the ComboBox value display in
the document, then:

Private Sub CommandButton1_Click()
Dim pStr As String
pStr = Left(Me.ComboBox1.Value, 8)
ActiveDocument.Tables(1).Cell(2, 3).Range.Text = pStr
Me.Hide
End Sub
 

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