Solved

Quick Access/VBA string function needed

Posted on 2013-12-20
4
510 Views
Last Modified: 2013-12-20
Dear experts -
Hopefully a quick one - I need a function that will give me a maximum of x characters of a string fed to it, BUT not in the middle of a word (defined as ending in a space or hyphen) UNLESS there is only a single word there.
Can anyone solve this little riddle?
Thanks!
0
Comment
Question by:terpsichore
4 Comments
 
LVL 57
ID: 39731599
Your going to need to write this if I'm understanding correctly.

Some examples would be good before we continue just to make sure were on the same page.

Jim.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39731618
So, if X characters ends in the middle of a word, what do you want, everything to the left of that word, or everything including that word?
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39731630
The riddle is in interpreting your question.
Does this do it?
Function GetString(strText As String, iCharCount As Integer) As String
    Dim p As Integer
    
    strText = Replace(strText, "-", " ")
    p = iCharCount
    
    Do While Mid(strText, p, 1) <> " "
        If p = 1 Then
            GetString = Left(strText, iCharCount)
            Exit Function
        Else
            p = p - 1
        End If
    Loop
    GetString = Left(strText, p)
End Function

Open in new window

0
 

Author Closing Comment

by:terpsichore
ID: 39731650
perfect. thanks so much.
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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

770 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