Solved

Returning characters from a string

Posted on 2011-03-16
3
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

632 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