Extract characters from a string

  • Follow


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 ~

0
Reply edouardlo 7/30/2007 6:51:20 AM

On Jul 30, 1:51 pm, edouar...@gmail.com 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

0
Reply luan 7/30/2007 9:00:29 AM


On Jul 30, 4:00 pm, luan <luanhox...@gmail.com> wrote:
> On Jul 30, 1:51 pm, edouar...@gmail.com 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

0
Reply luan 7/30/2007 9:03:40 AM

2 Replies
517 Views

(page loaded in 0.068 seconds)

Similiar Articles:
















7/19/2012 3:51:11 PM


Reply: