Re: How to split a field into parts

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Brendan Reynolds (anonymous)
Date: 03/08/05


Date: Tue, 8 Mar 2005 13:05:04 -0000

InStrRev *is* in Access 2000 - it was one of the new string functions that
were added to VBA 6, and Access 2000 was the first version to use VBA 6.
Some of those new functions could not be used directly in a query, though,
and I believe InStrRev was one of those. You'd have to write a custom VBA
function to call InStrRev, and then call the custom function from your
query.

In Access 97, you could do something like this ...

Public Function GetLastChar(ByVal TheString As String, ByVal TheChar As
String) As Long

    Dim lngLoop As Long
    Dim lngPos As Long

    For lngLoop = Len(TheString) To 1 Step -1
        If Mid$(TheString, lngLoop, 1) = TheChar Then
            lngPos = lngLoop
            Exit For
        End If
    Next lngLoop

    GetLastChar = lngPos

End Function

? getlastchar("this is some text", " ")
 13

-- 
Brendan Reynolds (MVP)
<doyle60@aol.com> wrote in message 
news:1110280264.316196.47990@g14g2000cwa.googlegroups.com...
> Thanks.  I do have Access 2000 at home and the InStrRev is certainly
> not a function in it.  Your HowManyChars works but I'm afraid I still
> need the position of the last Space in the string to split the name in
> half properly.
>
> Here are some sample names:
>
>   George Mitchell
>   Hank Natty Barnes
>   Nelly Margeret Stevens
>   Telsea "Minnie" Mack-Evens
>   Kent George Matty Gilbert Robertson
>
> I need to split them like this (I'll hand fix compound sir names):
>
>   George                        Mitchell
>   Hank Natty                    Barnes
>   Nelly Margeret                Stevens
>   Telsea "Minnie"               Mack-Evens
>   Kent George Matty Gilbert     Robertson
>
> I don't see how to do that without knowing the position of the last
> space.
>
> Basically I need a function that will help me put the last word in one
> field and all preceeding words in another.
>
> Thanks,
>
> Matt
>
>
>
>
>
> Brendan Reynolds wrote:
>> InStrRev was new in Access 2000. The best way to count the number of
> spaces
>> (or any other character) in a string uses Replace, but Replace was
> also new
>> in Access 2000. Here's an alternative, won't be as fast, but will
> work in
>> Access 97 ...
>>
>> Public Function HowManyChars(ByVal TheString As String, ByVal TheChar
> As
>> String) As Long
>>
>>     Dim lngLoop As Long
>>     Dim lngCount As Long
>>
>>     For lngLoop = 1 To Len(TheString)
>>         If Mid$(TheString, lngLoop, 1) = TheChar Then
>>             lngCount = lngCount + 1
>>         End If
>>     Next lngLoop
>>
>>     HowManyChars = lngCount
>>
>> End Function
>>
>> --
>> Brendan Reynolds (MVP)
>>
>> <doyle60@aol.com> wrote in message
>> news:1110228530.226532.143100@f14g2000cwb.googlegroups.com...
>> > Thanks.  But InStrRev is not a defined function in my Access 1997.
> I'm
>> > trying to use it in a query, if that matters.
>> >
>> > I still need a function that tells me how many spaces are in a
> string?
>> > But if I get the InStrRev to work, I could just say: if InStr is
> equal
>> > to InStrRev, then this, and if not, that.  Now I'm thinking.
> Thanks,
>> >
>> > Matt
>> >
> 


Relevant Pages

  • Re: How to split a field into parts
    ... I do have Access 2000 at home and the InStrRev is certainly ... Your HowManyChars works but I'm afraid I still ... Kent George Matty Gilbert Robertson ... > in a string uses Replace, ...
    (microsoft.public.access.modulesdaovba)
  • RE: VBA - Find command
    ... Find in VBA is equivalent to Ctrl + F or Edit -> Find. ... There is also InstrRev to find the last instance of a string within a ... (e.g. Smith Bob space is located in postion 6) ...
    (microsoft.public.excel.programming)
  • Re: No InStrRev func in JET SQL (vb6 + ADO2.8 + Access2000)
    ... But as I see the InStrRev func doesn't work (as well as Replace and some ... Public Function InStrReverse(ByVal strText As String, ... Dim intIndex As Integer ...
    (microsoft.public.vb.database.ado)
  • Re: No InStrRev func in JET SQL (vb6 + ADO2.8 + Access2000)
    ... But as I see the InStrRev func doesn't work (as well as Replace and some ... Public Function InStrReverse(ByVal strText As String, ByVal strSearch As ... Dim intIndex As Integer ...
    (microsoft.public.vb.database.ado)
  • Re: Seperating Extension and File Name
    ... The InStrRevfunction will find the first period, searching from the end of the string: ... I'd suggest that you read up on the InStrRev, Left and Mid functions in Help, now that you've seen them in action. ... Dim Atmt As Attachment ... Dim fName As String ...
    (microsoft.public.outlook.program_vba)