473,748 Members | 8,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to extract numbers from a memo field and sum them.

3 New Member
I have a memo field with a mixture of numbers and text. I would like to add up all the numeric values to obtain a total. Numbers can be in the format 01 or 1, all numbers are no more than 2 digits, but may not have a space before the text.
Oct 23 '10 #1
6 2314
mshmyob
904 Recognized Expert Contributor
Give us a little more info or better yet a sample of the data stream.

Are the numbers on different lines or all bundled together?

cheers,
Oct 23 '10 #2
Peter Thomson
3 New Member
The numbers are on the same line. Example :
05VGML/03SFML/01GFML-DAIRY FREE MEAL/04FPML

or it could be:

5 VGML 3 SFML 1 GFML Dairy Free Meal 4 FPML.

It all depends on the style of the data inputter.

I need to add up the total of all the numbers from each Memo field.
And (only if possible) exclude numbers before certain text, ie. BBML.

Hope this is clear.
Oct 23 '10 #3
ADezii
8,834 Recognized Expert Expert
This one was a little tricky, but I do feel as though I have arrived at a viable solution. First, a couple of assumptions.
  • Table Name is Table1 (modify to your needs).
  • Field1 is a Field in Table1 of Type MEMO (modify to your needs).
  • The Code Logic assumes that only Single or Double Digits can exist in the MEMO Field, interspersed among various Characters including Spaces.
  • For each Record, the Query will call on a Public Function via a Calculated Field (Numeric_Total) , and return an Aggregate Total of all Digits that exist in the MEMO Field.
  • The MEMO Field may be NULL, since the Function will return NULL.
  • Any questions, feel free to ask.
  1. Function Definition:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fCalcTotals_2(varMEMO As Variant) As Variant
    2. Dim lngLenOfString As Long
    3. Dim lngCharPos As Long
    4. Dim lngBuild
    5.  
    6. If IsNull(varMEMO) Then
    7.   fCalcTotals_2 = Null
    8.     Exit Function
    9. End If
    10.  
    11. lngLenOfString = Len(varMEMO)
    12.  
    13. lngBuild = 0        'Initialize
    14. lngCharPos = 1      'Initialize
    15.  
    16. 'Check every Character in the String (MEMO Field). If the Character is
    17. 'Numeric, see if the next Character is Numeric since a Number can only be
    18. '1 or 2 Digts. Add to a pre-existing Long Variable to accumulate a Total.
    19. 'This process cannot be performed on the last Character in the String.
    20. Do While lngCharPos <= lngLenOfString
    21.   If IsNumeric(Mid$(varMEMO, lngCharPos, 1)) Then         'Is the Character Numeric?
    22.     'Is the Character after it Numeric, but not for the last Character?
    23.     If IsNumeric(Mid$(varMEMO, lngCharPos, 2)) And lngCharPos <> lngLenOfString Then
    24.       lngBuild = lngBuild + Val(Mid$(varMEMO, lngCharPos, 2))
    25.         lngCharPos = lngCharPos + 2     '2-Digits, advance Position by 2
    26.     Else        'Character after is not Numeric
    27.       lngBuild = lngBuild + Val(Mid$(varMEMO, lngCharPos, 1))
    28.         lngCharPos = lngCharPos + 1     '1-Digit, advance Position by 1
    29.     End If
    30.   Else
    31.     lngCharPos = lngCharPos + 1         'Non-Numeric, advance by 1
    32.   End If
    33. Loop
    34.  
    35. fCalcTotals_2 = lngBuild
    36. End Function
  2. SQL Statement for Query:
    Expand|Select|Wrap|Line Numbers
    1. SELECT Table1.Field1, fCalcTotals_2([Field1]) AS Numeric_Total
    2. FROM Table1;
  3. Results after Query Execution (Sample Data):
    Expand|Select|Wrap|Line Numbers
    1. Field1                                   Numeric_Total    
    2.  1 A 2 B 5 HYTR 2       TTRY                   10
    3. 10 20 30 YYYTRRRR 40                          100
    4. 22LLOUUTDSR16 7 9 21HHFF  22                   97
    5. 55FF45    19    2                             121
    6. F                                               0
    7. ULKH1LKLKL7        55                          63
Oct 23 '10 #4
ADezii
8,834 Recognized Expert Expert
@Peter:
I tested the Code against new newly posted Sample Data in Post #2, and it appears to work quite well. Results are posted below:
Expand|Select|Wrap|Line Numbers
  1. Field1                                          Numeric_Total
  2. 05VGML/03SFML/01GFML-DAIRY FREE MEAL/04FPML          13
  3. 5 VGML 3 SFML 1 GFML Dairy Free Meal 4 FPML.         13
Oct 23 '10 #5
Peter Thomson
3 New Member
Wow, thank you. Works perfectly.
First time I have asked for help, and I am so glad I did.

Thank you very much.
Oct 24 '10 #6
ADezii
8,834 Recognized Expert Expert
You are quite welcome.
Oct 24 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
10474
by: Shyguy | last post by:
I want to create two buttons on a form. One would allow the user to Copy the contents of the current records memo field, the other would allow them to print. I set up a report based on the memo field, and it works. But, it seems wrong since I had to create a huge text box to accommodate memo fields with a lot of text. Thanks for any help, ShyGuy
16
4881
by: Mark | last post by:
Hello. I am attempting to use AppendChunk() to write binary data to a memo field in Access 2000. My initial call to AppendChunk() results in a data type conversion error. Any suggestions? Here is a VBA function which demonstrates the problem. Thanks -Mark
5
1986
by: klall | last post by:
Hello. I need to extract date information from a memo field entered in the following way: 01/01/2005 - 31/12/2005 01/01/2004 - 31/12/2004 01/01/2003 - 31/12/2003 01/01/1996 - 31/12/1996. The number of entries varies. I would welcome advice on a more elegant way of extracting all the date information (first date, second date, third date, etc and appending to another table, say tblDates) rather than the crude way I have used left
4
7239
by: Mark Reed | last post by:
Hi All, here is what I am trying to achieve. I have a memo field on a form which users will need to add to as and when. I do not want them to be able to edit information which already exists within this field. My idea was to have the memo field locked on the form to stop edits. Place a command button by the memo field which opens an unbound form with a single text box. The user enters their update into the unbound form and upon closing...
6
5957
by: Dave | last post by:
Hope someone can help! I have a memo fiels in which there are a few numbers including dates but what I want to do is extract a number which is 6 figures long. Can anyone help me? Thanks Dave
9
5737
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo field is printed within the detailed area. The problem is, the apllication is not setup properly, thus the users are entering data within the memo field as: location1 1/1/2005 1/1/2006
5
4941
by: Bluecove | last post by:
After many unsuccessful attempts at this, including the use of software from Sobolsoft, I need help! I have a table comprised of thousands of long records (all in one column which is Memo type). These records are from an old Dos-based database. I need to extract text from each memo fields and put it into it's proper place. For example, a part of the memo field looks like this: <A>JOYCE, James.<T>Dubliners<DATE>1933<PUB>..etc. I need to strip...
2
3384
by: Roger | last post by:
I've got two tables in sql2005 which have an 'ntext' field when I linked the first table in access97 last week using an odbc data source the access-field type was 'memo' when I link the 2nd table today, it is linked as a text(255) field, ditto for the first table if I link it today if I link the 2nd table using access2003 (and the same odbc data source) it is linked as a memo field
1
2325
by: Ibergarden | last post by:
Hello, I need to extract three text lines from a memo field (created by exporting messages from outlook) and separate them into individual fields. Does anybody can help me? Thank you
0
8991
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9321
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8242
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3312
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
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.