473,506 Members | 17,000 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 2547
> 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(strStringToMatch 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("VBScript.RegExp")
Set rst = db.OpenRecordset("qrySelectFieldsToSearch")
strNeedle = LCase(strStringToMatch)
Do While Not rst.EOF
strHaystack = LCase(GetSomeString(rst!Haystack))
objRgx.Pattern = "\b" & strNeedle
If objRgx.Test(strHaystack) 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(OldString) 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
6198
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...
8
3326
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...
11
9089
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...
8
7242
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...
4
2585
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...
12
2607
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...
6
27460
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...
9
2238
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 ..... ...
3
8872
by: sam | last post by:
same as subject?
0
7218
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,...
0
7103
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...
0
7307
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,...
0
7370
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...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
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,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
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...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.