Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / May 2005

Tip: Looking for answers? Try searching our database.

Fixing Number Of words!!!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kennykee - 06 May 2005 04:53 GMT
How to fix total number of words in a field?
eg.
30 X 30 ==> 3 words
50 X 89 ==> 3 words
80X 21 ==>2 words==>error message & delete

Any solutions?

Thanks in advance

Kennykee
Dirk Goldgar - 06 May 2005 05:05 GMT
> How to fix total number of words in a field?
> eg.
[quoted text clipped - 3 lines]
>
> Any solutions?

Here's a function that returns an array of the blank-delimited words in
the string you pass it:

'----- start of code -----
Function SplitWords( _
           ByVal pstrSource As String, _
           Optional pstrDelim As String = " ", _
           Optional plngLimit As Long = -1, _
           Optional pCompare As Long = vbBinaryCompare) _
       As String()

   ' Split the argument pstrSource into an array of "words"
   ' based on the delimiter passed as pstrDelim, treating
   ' consecutive occurrences of the delimiter as a single
   ' occurrence.  So, for example, SplitWords("This   Function")
   ' returns the same output array as SplitWords("This Function").

   Dim strTwoDelim As String
   Dim lngLen As Long

   strTwoDelim = pstrDelim & pstrDelim

   Do
       lngLen = Len(pstrSource)
       pstrSource = _
           Replace(pstrSource, strTwoDelim, pstrDelim, 1, -1, pCompare)
   Loop Until Len(pstrSource) = lngLen

   SplitWords = Split(pstrSource, pstrDelim, plngLimit, pCompare)

End Function
'----- end of code -----

With that function saved in a standard module, you can count the number
of words in a field like this:

   intWords = UBound(SplitWords([YourField])) + 1

In a BeforeUpdate event procedure, you might say something like:

   If UBound(SplitWords([YourField])) + 1 <> 3 Then
       MsgBox "That's not a valid measurement."
       Cancel = True
   End If

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

kennykee - 06 May 2005 07:40 GMT
That's really complex but it really works
Thanks Dirk

> > How to fix total number of words in a field?
> > eg.
[quoted text clipped - 48 lines]
>         Cancel = True
>     End If
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.