Only using part of the info of a text field

M

Matt

Thanks for your help in my last question Rdub, worked a treat.

Hi

This is similar to my last question, I am creating an excel document using
info from some database fields (part of code below). In the phContactName
field info is inputted as follows "name (other info)". I want to use the name
before the ( in the spreadsheet. Is there an easy way of doing this ?

Thanks
Matt

With xlSheet
.Cells(10, 1).Value = Me.phContactname
.Cells(27, 3).Value = Me.phAddress
.Cells(7, 3).Value = Me.phTown
End With
 
M

Matt

Thanks that works
the only problem is on some occasions the are no brackets in the field
which brings up an error and breaks the code. Is there any way round this, so
if there are no brackets it just uses the whole field.
 
D

Danny Seager

how about

If nz(InStr(Me.phContactName, "("),0)> 0 then
Trim(Left(Me.phContactName, InStr(Me.phContactName, "(") - 1))
else
Me.phContactName
end if
 
M

Matt

Thanks alot its all working now

Danny Seager said:
how about

If nz(InStr(Me.phContactName, "("),0)> 0 then
Trim(Left(Me.phContactName, InStr(Me.phContactName, "(") - 1))
else
Me.phContactName
end if
 

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