I need to divide a word

J

Jimmy

I have a field wich is called "Totalname". That field contains surnames.
What I need is to have the two last letters of each word of that field into
another new field which I'll name it"Newfield". Can someone help me please.
Thanks
Jimmy
 
A

Al Borges

Hi Jimmy:

Do you wish to have the last 2 letters of each record's [Totalname] field
placed into [Newfield], or does Totalname have several words? For example,
if you have John Doe MD, you want "MD"? or "hnoeMD"? The former is easy-
just do a [Newfield] = Right([Totalname], 2); with the latter I'd do
something like-

Dim ii As Integer, value As String, xx As String, yy As String
xx = ""
value = [Totalname]
For ii=1 to Len(value)
yy = Mid(value, ii, 1)
If yy <> " " Then
xx = xx + yy
Else ' word separator " "
If isnull([newfield1]) then
[NewField1] = Right(xx,2) ' s.a. the first name's last 2 digits
else
If IsNull([NewField2]) Then
[NewField2] = Right(xx,2) ' s.a. the last name's last 2 digits
Else
[NewField3] = Right(xx,2) ' s.a. the title's last 2 digits
End If
End If
End If
Next i

That's it... should work without too many bugs... :cool:

Regards,
Al
 
J

Jimmy

Thank you for your answer Al. My situation is the "hnoeMD"? So which code
should I use?


Al Borges said:
Hi Jimmy:

Do you wish to have the last 2 letters of each record's [Totalname] field
placed into [Newfield], or does Totalname have several words? For example,
if you have John Doe MD, you want "MD"? or "hnoeMD"? The former is easy-
just do a [Newfield] = Right([Totalname], 2); with the latter I'd do
something like-

Dim ii As Integer, value As String, xx As String, yy As String
xx = ""
value = [Totalname]
For ii=1 to Len(value)
yy = Mid(value, ii, 1)
If yy <> " " Then
xx = xx + yy
Else ' word separator " "
If isnull([newfield1]) then
[NewField1] = Right(xx,2) ' s.a. the first name's last 2 digits
else
If IsNull([NewField2]) Then
[NewField2] = Right(xx,2) ' s.a. the last name's last 2 digits
Else
[NewField3] = Right(xx,2) ' s.a. the title's last 2 digits
End If
End If
End If
Next i

That's it... should work without too many bugs... :cool:

Regards,
Al



Jimmy said:
I have a field wich is called "Totalname". That field contains surnames.
What I need is to have the two last letters of each word of that field into
another new field which I'll name it"Newfield". Can someone help me please.
Thanks
Jimmy
 
A

Al Borges

Hi Jimmy:

You only have to change this code snippet to the following (everything else
is OK):

Dim ii As Integer, value As String, xx As String, yy As String
xx = ""
value = [Totalname]
For ii=1 to Len(value)
yy = Mid(value, ii, 1)
If yy <> " " Then
xx = xx + yy
Else ' word separator " "
yy = IIf(IsNull([NewField]), "", [NewField])
[NewField] = yy & Right(xx,2)
End If
Next i

Now that should do it!

Regards,
Al


Jimmy said:
Thank you for your answer Al. My situation is the "hnoeMD"? So which code
should I use?


Al Borges said:
Hi Jimmy:

Do you wish to have the last 2 letters of each record's [Totalname] field
placed into [Newfield], or does Totalname have several words? For example,
if you have John Doe MD, you want "MD"? or "hnoeMD"? The former is easy-
just do a [Newfield] = Right([Totalname], 2); with the latter I'd do
something like-

Dim ii As Integer, value As String, xx As String, yy As String
xx = ""
value = [Totalname]
For ii=1 to Len(value)
yy = Mid(value, ii, 1)
If yy <> " " Then
xx = xx + yy
Else ' word separator " "
If isnull([newfield1]) then
[NewField1] = Right(xx,2) ' s.a. the first name's last 2 digits
else
If IsNull([NewField2]) Then
[NewField2] = Right(xx,2) ' s.a. the last name's last 2 digits
Else
[NewField3] = Right(xx,2) ' s.a. the title's last 2 digits
End If
End If
End If
Next i

That's it... should work without too many bugs... :cool:

Regards,
Al



Jimmy said:
I have a field wich is called "Totalname". That field contains surnames.
What I need is to have the two last letters of each word of that field into
another new field which I'll name it"Newfield". Can someone help me please.
Thanks
Jimmy
 
J

Jimmy

Thanks Al. Can you please tell me where exactly should I write that code. I
am a newbe in Access.
Thank You


Al Borges said:
Hi Jimmy:

You only have to change this code snippet to the following (everything
else
is OK):

Dim ii As Integer, value As String, xx As String, yy As String
xx = ""
value = [Totalname]
For ii=1 to Len(value)
yy = Mid(value, ii, 1)
If yy <> " " Then
xx = xx + yy
Else ' word separator " "
yy = IIf(IsNull([NewField]), "", [NewField])
[NewField] = yy & Right(xx,2)
End If
Next i

Now that should do it!

Regards,
Al


Jimmy said:
Thank you for your answer Al. My situation is the "hnoeMD"? So which
code
should I use?


Al Borges said:
Hi Jimmy:

Do you wish to have the last 2 letters of each record's [Totalname] field
placed into [Newfield], or does Totalname have several words? For example,
if you have John Doe MD, you want "MD"? or "hnoeMD"? The former is
easy-
just do a [Newfield] = Right([Totalname], 2); with the latter I'd do
something like-

Dim ii As Integer, value As String, xx As String, yy As String
xx = ""
value = [Totalname]
For ii=1 to Len(value)
yy = Mid(value, ii, 1)
If yy <> " " Then
xx = xx + yy
Else ' word separator " "
If isnull([newfield1]) then
[NewField1] = Right(xx,2) ' s.a. the first name's last 2 digits
else
If IsNull([NewField2]) Then
[NewField2] = Right(xx,2) ' s.a. the last name's last 2 digits
Else
[NewField3] = Right(xx,2) ' s.a. the title's last 2 digits
End If
End If
End If
Next i

That's it... should work without too many bugs... :cool:

Regards,
Al



I have a field wich is called "Totalname". That field contains surnames.
What I need is to have the two last letters of each word of that field
into
another new field which I'll name it"Newfield". Can someone help me
please.
Thanks
Jimmy
 
A

Al Borges MD

Hi Jimmy:

You could write it numerous events- I would probably consider a clickbutton
event, into a doubleclick event of a textbox.

Regards,
Al

Jimmy said:
Thanks Al. Can you please tell me where exactly should I write that code. I
am a newbe in Access.
Thank You


Al Borges said:
Hi Jimmy:

You only have to change this code snippet to the following (everything
else
is OK):

Dim ii As Integer, value As String, xx As String, yy As String
xx = ""
value = [Totalname]
For ii=1 to Len(value)
yy = Mid(value, ii, 1)
If yy <> " " Then
xx = xx + yy
Else ' word separator " "
yy = IIf(IsNull([NewField]), "", [NewField])
[NewField] = yy & Right(xx,2)
End If
Next i

Now that should do it!

Regards,
Al


Jimmy said:
Thank you for your answer Al. My situation is the "hnoeMD"? So which
code
should I use?


Hi Jimmy:

Do you wish to have the last 2 letters of each record's [Totalname] field
placed into [Newfield], or does Totalname have several words? For example,
if you have John Doe MD, you want "MD"? or "hnoeMD"? The former is
easy-
just do a [Newfield] = Right([Totalname], 2); with the latter I'd do
something like-

Dim ii As Integer, value As String, xx As String, yy As String
xx = ""
value = [Totalname]
For ii=1 to Len(value)
yy = Mid(value, ii, 1)
If yy <> " " Then
xx = xx + yy
Else ' word separator " "
If isnull([newfield1]) then
[NewField1] = Right(xx,2) ' s.a. the first name's last 2 digits
else
If IsNull([NewField2]) Then
[NewField2] = Right(xx,2) ' s.a. the last name's last 2 digits
Else
[NewField3] = Right(xx,2) ' s.a. the title's last 2 digits
End If
End If
End If
Next i

That's it... should work without too many bugs... :cool:

Regards,
Al



I have a field wich is called "Totalname". That field contains surnames.
What I need is to have the two last letters of each word of that field
into
another new field which I'll name it"Newfield". Can someone help me
please.
Thanks
Jimmy
 
Top