473,569 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read part of the data in text field

Hi everyone,

I am searching a way to read part of the data in the text field in a
form. As the length of the field is dynamic, I can't use the left or
right function. I need to read the first 2 words from the specific
control like:

Get "January 2005" from "January 2005 final", or "January 2005 test
samples", what I need is the first two words. What function I can use?

Any help will be greatly appreciated!

Thanks in advance!

Shelley

Nov 13 '05 #1
2 2554
> I am searching a way to read part of the data in the text field in a
form. As the length of the field is dynamic, I can't use the left or
right function. I need to read the first 2 words from the specific
control like:

Get "January 2005" from "January 2005 final", or "January 2005 test
samples", what I need is the first two words. What function I can use?


This is a job for Regex. Though not really an Access function, this should
work on 2000/XP machines (the joker in the pack is the version of the
VBScript engine). This code will get you started but you'll need to brush
up on Regex syntax to match the text you're looking for.

Public Function MatchString(str StringToMatch As String)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strNeedle As String
Dim strHaystack As String
Dim objRgx As Object
Set db = CurrentDb
Set objRgx = CreateObject("V BScript.RegExp" )
Set rst = db.OpenRecordse t("qrySelectFie ldsToSearch")
strNeedle = LCase(strString ToMatch)
Do While Not rst.EOF
strHaystack = LCase(GetSomeSt ring(rst!Haysta ck))
objRgx.Pattern = "\b" & strNeedle
If objRgx.Test(str Haystack) Then
[do whatever]
Exit Do
End If
End If
rst.MoveNext
Loop
Set rst = Nothing
Set db = Nothing
Set objRgx = Nothing
End Function
Nov 13 '05 #2
On 21 Feb 2005 09:43:58 -0800, Shelley wrote:
Hi everyone,

I am searching a way to read part of the data in the text field in a
form. As the length of the field is dynamic, I can't use the left or
right function. I need to read the first 2 words from the specific
control like:

Get "January 2005" from "January 2005 final", or "January 2005 test
samples", what I need is the first two words. What function I can use?

Any help will be greatly appreciated!

Thanks in advance!

Shelley


Is the second word always 4 characters (2004, 2005, etc.)?

Left([CombinedNames],(InStr([CombinedNames]," "))) &
Mid([CombinedNames],InStr([CombinedNames]," ")+1,4)

If the second word length varies:
Copy and paste the below code to a Module:

Public Function FindString(OldS tring) As String
' find the first 2 words within a string

Dim intX As Integer
Dim intY As Integer

intX = InStr(1, OldString, " ")
intY = InStr(intX + 1, OldString, " ")
FindString = Left(OldString, intY - 1)

End Function
==============
Call it from a query:
Exp:FindString([CombinedNames])
Or...
In an unbound control in a form or report:
= FindString([CombinedNames])

--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
6208
by: AnnMarie | last post by:
<script language="JavaScript" type="text/javascript"> <!-- function validate(theForm) { var validity = true; // assume valid if(frmComments.name.value=='' && validity == true) { alert('Your full name is required. Please enter your full name!'); validity = false; frmComments.name.focus();
8
3337
by: horos | last post by:
hey all, Ok, a related question to my previous one on data dumpers for postscript. In the process of putting a form together, I'm using a lot of placeholder variables that I really don't care about in the submitted action. I'd therefore like to get rid of them by doing something like:
11
9114
by: Pete | last post by:
Is there any way to change the default search to "Any Part Of Field" instead of whole field? The first thing I ever do when searching for something in a field is change the default setting from "Whole Field" to "Any part of field" because that way I don't have to key in the entire word I'm searching for. It is especially frustrating having...
8
7246
by: james | last post by:
I am trying to use Filestream to read a file ( .DAT) that contains values in HEX that I want to convert to text. I know the different offset addresses for each portion of the data I am trying to retrieve. But, I am having problems actually reading the data for the number of Bytes that I need to get from each address. Here is some of the code I...
4
2587
by: Antonio Tirado | last post by:
Hi, I'm using the OleDB namespace to open a CSV File. I can read the file sucessfully except for hyphenated values. My CSV File contains phone numbers and sometimes these come separated with hyphens (ie: 555-123-4567). These fields come as empty using the OleDB namespace and as dbNull when using the ODBC namespace. Is there a way to prevent...
12
2615
by: Ima Loozer | last post by:
OK folks here is what I need help with. Lets assume I have a text field that will contain AlphaNumeric data. There is no set pattern to the field such that any given character can be either alpha or numeric. I need a function that will return the requested 'part' of the contents of the field. A 'part' would be defined as consecutive Alpha...
6
27482
by: Jim S | last post by:
I have a need to read the contents of an html table on a remote web page into a variable. I guess this is called screen scraping but not sure. I'm not sure where to start or what the best practices are to accomplish this. For instance; I have a healthcare app that need to check a gov't we page for a user's license no# periodically. There...
9
2246
by: Hollywood | last post by:
Hello members of the comp.lang.c++, My log file is made of a set of 1000 following lines kind: 21/09/07 13:49:56,MW.SET.D_IGLS,2.000000 21/09/07 13:49:56,MW.SET.GNP_NT,7.000000 ..... commas ',' are used as field separators (data, name, value).
3
8887
by: sam | last post by:
same as subject?
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.