Solved

Returning characters from a string

Posted on 2011-03-16
3
322 Views
Last Modified: 2012-05-11
Hello,

I have a field containing the following type of string data.  I want to create a field in a query that extracts and displays 2.09.56 So I need to find the position of the third occurence of the period.  and then use a MID function to do the actual extraction.  How do I find a specified occurance of a characer
2.09.56.25.67303.00.P09
0
Comment
Question by:chtullu135
3 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 35148639
it will be better to use a function.
place this function in a regular module

function getX(s) as string
if s & ""="" or isnull(s) then getX="":exit function

dim arS,j, strX

ars=split(s,".")
for j=0 to 2
  strx = strx & "." & arS(j)
next

getX=mid(strx,2)

end function


yo use in your query

select f1, getx([f1]) as newfield from table

0
 
LVL 17

Expert Comment

by:JezWalters
ID: 35149278
Or you could do it like this:

    Option Explicit
    Option Base 0

    Public Function GetDate(pvarField As Variant) As Variant

        Dim astrComponents() As String

        astrComponents = Split(Nz(pvarField), ".")
        If UBound(astrComponents) > 2 Then
            ReDim Preserve astrComponents(2) As String
            GetDate = Join(astrComponents, ".")
        Else
            GetDate = Null
        End If

    End Function

, with am acommpanying query like this:

    SELECT YourField, GetDate(YourField) AS FieldDate
    FROM YourTable
0
 

Author Closing Comment

by:chtullu135
ID: 35151826
Thanks,

I appreciate the help.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now