Extract characters from a string

E

edouardlo

I would like to extract characters from a string field. I tried this
function: left(info, 2), the extracted character would be "in".
However, info is actually a field name which contants 1A_Peter. What
I want to extract is 1A instead.
How can I solve this problem?
THX ~
 
L

luan

I would like to extract characters from a string field. I tried this
function: left(info, 2), the extracted character would be "in".
However, info is actually a field name which contants 1A_Peter. What
I want to extract is 1A instead.
How can I solve this problem?
THX ~
Hi, try use:

In Modules write this code:
Function Extractstring(ByVal InString As String) As String
If InStr(InString, "_") <> 0 Then
Extract1 = Left(InString, Len(InString) - InStr(InString, "_") -
1)
Else: Extractstring = InString
End If
End Function

In controlsource of textbox use: = Extractstring([info])

HTH
Luan
 
L

luan

On Jul 30, 1:51 pm, (e-mail address removed) wrote:> I would like to extract characters from a string field. I tried this
function: left(info, 2), the extracted character would be "in".
However, info is actually a field name which contants 1A_Peter. What
I want to extract is 1A instead.
How can I solve this problem?
THX ~

Hi, try use:

In Modules write this code:
Function Extractstring(ByVal InString As String) As String
If InStr(InString, "_") <> 0 Then
Extract1 = Left(InString, Len(InString) - InStr(InString, "_") -
1)
Else: Extractstring = InString
End If
End Function

In controlsource of textbox use: = Extractstring([info])

HTH
Luan

Hi, sorry there is typing mistake:

Function Extractstring(ByVal InString As String) As String
If InStr(InString, "_") <> 0 Then
Extractstring = Left(InString, Len(InString) - InStr(InString,
"_") - 1)
Else: Extractstring = InString
End If
End Function

;-)
Luan
 

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