I have a text field on a form which has names with a comma between them like
this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a
procedure that will count the number of people in this text box and put the
number into another text box (4 in the case above). If I could count the
number of commas + 1, this would do it. Can anyone please help me with a
way to achieve this?
dixie 6 7449
On Thu, 16 Sep 2004 09:52:27 +1000, dixie wrote: I have a text field on a form which has names with a comma between them like this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a procedure that will count the number of people in this text box and put the number into another text box (4 in the case above). If I could count the number of commas + 1, this would do it. Can anyone please help me with a way to achieve this?
dixie
Air code:
In a module:
Function CountCommas(Str ingIn as String) as String
Dim intX as Integer
Dim intY as integer
intX = InStr(StringIn, ",")
Do While intX <> 0
intY = intY + 1
intX = InStr(intX + 1,StringIn,",")
Loop
CountCommas = intY
End Function
You can call it from a query.
Words: CountCommas([FieldName]) + 1
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Easiest way is to use the Split function:
Public Function CountStringItem s( _
Items As String, _
Delim As String _
) As Long
Dim varaItems As Variant
varaItems = Split(Items, Delim)
CountStringItem s = ArrayCount(vara Items)
End Function
Public Function ArrayCount(varA rray As Variant)
ArrayCount = UBound(varArray ) - LBound(varArray ) + 1
End Function
On Thu, 16 Sep 2004 09:52:27 +1000, "dixie" <di****@dogmail .com> wrote: I have a text field on a form which has names with a comma between them like this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a procedure that will count the number of people in this text box and put the number into another text box (4 in the case above). If I could count the number of commas + 1, this would do it. Can anyone please help me with a way to achieve this?
dixie
On Thu, 16 Sep 2004 02:41:48 GMT, fredg wrote: On Thu, 16 Sep 2004 09:52:27 +1000, dixie wrote:
I have a text field on a form which has names with a comma between them like this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a procedure that will count the number of people in this text box and put the number into another text box (4 in the case above). If I could count the number of commas + 1, this would do it. Can anyone please help me with a way to achieve this?
dixie
Air code: In a module: Function CountCommas(Str ingIn as String) as String Dim intX as Integer Dim intY as integer intX = InStr(StringIn, ",") Do While intX <> 0 intY = intY + 1 intX = InStr(intX + 1,StringIn,",") Loop CountCommas = intY End Function
You can call it from a query. Words: CountCommas([FieldName]) + 1
I gave you information on how to count commas in a field, but your
basic quest is to separate text into various fields.
You don't need to count the commas.
Look up the Split() function in VBA help.
It will parse the field without need for this counting function.
Public Function ParseText(TextI n As String, X) As Variant
On Error Resume Next
Dim var As Variant
var = Split(TextIn, ",", -1)
ParseText = var(X)
End Function
============
Call it from a query:
Name1:ParseText ([Fullfield],0)
Name2:ParseText ([FullField],1)
etc.
Note that the array is zero based.
You get 2 functions today for the price of one. :-)
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
I am a little at a loss as to how to run this on my form to count the names
in the text box txtNames which has names separated by commas. Sorry, but
I'm not good with public functions. I have put it into the main module, but
how do I use it on the form?
dixie
"Steve Jorgensen" <no****@nospam. nospam> wrote in message
news:dp******** *************** *********@4ax.c om... Easiest way is to use the Split function:
Public Function CountStringItem s( _ Items As String, _ Delim As String _ ) As Long Dim varaItems As Variant varaItems = Split(Items, Delim) CountStringItem s = ArrayCount(vara Items) End Function
Public Function ArrayCount(varA rray As Variant) ArrayCount = UBound(varArray ) - LBound(varArray ) + 1 End Function
On Thu, 16 Sep 2004 09:52:27 +1000, "dixie" <di****@dogmail .com> wrote:
I have a text field on a form which has names with a comma between them
likethis: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a procedure that will count the number of people in this text box and put
thenumber into another text box (4 in the case above). If I could count the number of commas + 1, this would do it. Can anyone please help me with a way to achieve this?
dixie
Well, where does the value get used, and how? Do you mean it's displayed in
another control on the form? If so, you could set the Control Source property
of that control to =CountStringIte ms([txtNames] & "", ",").
The [txtNames] & "" part converts the value to a blank string if it is Null.
Ichecked, and the function correctly returns 0 for a blank string.
On Fri, 17 Sep 2004 13:57:46 +1000, "dixie" <di****@dogmail .com> wrote: I am a little at a loss as to how to run this on my form to count the names in the text box txtNames which has names separated by commas. Sorry, but I'm not good with public functions. I have put it into the main module, but how do I use it on the form?
dixie
"Steve Jorgensen" <no****@nospam. nospam> wrote in message news:dp******* *************** **********@4ax. com... Easiest way is to use the Split function:
Public Function CountStringItem s( _ Items As String, _ Delim As String _ ) As Long Dim varaItems As Variant varaItems = Split(Items, Delim) CountStringItem s = ArrayCount(vara Items) End Function
Public Function ArrayCount(varA rray As Variant) ArrayCount = UBound(varArray ) - LBound(varArray ) + 1 End Function
On Thu, 16 Sep 2004 09:52:27 +1000, "dixie" <di****@dogmail .com> wrote:
>I have a text field on a form which has names with a comma between themlike >this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a >procedure that will count the number of people in this text box and putthe >number into another text box (4 in the case above). If I could count the >number of commas + 1, this would do it. Can anyone please help me with a >way to achieve this? > >dixie >
Steve, your a genius. That worked straight away. I can even see it
dynamically updating on the screen as I add people to the text box. Thanks
for your kind help.
dixie
"Steve Jorgensen" <no****@nospam. nospam> wrote in message
news:2c******** *************** *********@4ax.c om... Well, where does the value get used, and how? Do you mean it's displayed
in another control on the form? If so, you could set the Control Source
property of that control to =CountStringIte ms([txtNames] & "", ",").
The [txtNames] & "" part converts the value to a blank string if it is
Null. Ichecked, and the function correctly returns 0 for a blank string.
On Fri, 17 Sep 2004 13:57:46 +1000, "dixie" <di****@dogmail .com> wrote:
I am a little at a loss as to how to run this on my form to count the
namesin the text box txtNames which has names separated by commas. Sorry, but I'm not good with public functions. I have put it into the main module,
buthow do I use it on the form?
dixie
"Steve Jorgensen" <no****@nospam. nospam> wrote in message news:dp******* *************** **********@4ax. com... Easiest way is to use the Split function:
Public Function CountStringItem s( _ Items As String, _ Delim As String _ ) As Long Dim varaItems As Variant varaItems = Split(Items, Delim) CountStringItem s = ArrayCount(vara Items) End Function
Public Function ArrayCount(varA rray As Variant) ArrayCount = UBound(varArray ) - LBound(varArray ) + 1 End Function
On Thu, 16 Sep 2004 09:52:27 +1000, "dixie" <di****@dogmail .com> wrote:
>I have a text field on a form which has names with a comma between
themlike >this: 'J. Smith, A. Jones, A. Man, J. Johns'. I am trying to find a >procedure that will count the number of people in this text box and
putthe >number into another text box (4 in the case above). If I could count
the >number of commas + 1, this would do it. Can anyone please help me
with a >way to achieve this? > >dixie > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike N. |
last post by:
Hello:
I have a form that contains a multiple-select field that has 12
options in it. I would like the user to be able to select UP TO FOUR
of those options. If they select more than four, I would like to alert
them of the error. To do this, I figure that counting commas would be
the easiest method (i.e., IF commas > 3 THEN alert user).
NOTE: I have an existing "validateForm" function for this form and I'd
like to add this IF-THEN...
|
by: AES |
last post by:
Encountered a URL containing a comma the other day -- the first time
I've ever noticed that, so far as I can recall. It worked fine,
however, and I gather commas are legal in URLs.
Out of curiosity, did a quick scan of an ASCII file of the 542 URLs in
my personal bookmark file and discovered exactly 3 that contained commas
(two with a single comma, one with three commas) -- so I guess they're
pretty rarely used, even if legal.
Seems...
|
by: DrNoose |
last post by:
Hi!
I'm writing a program that is supposed to read a line of input, count
the words and the number of occurrences of each letter. Then it should
prints the number of occurrences of each letter that appears in the
input line. For example, if I typed "I say Hi." it should give the
following output:
3 words
1 a
|
by: Megan |
last post by:
hi everybody-
i'm having a counting problem i hope you guys and gals could give me
some help with. i have a query that retrieves a bevy of information
from several different tables.
first let me give you a little background. this database is kind of
like a human resources database. it collects info about people, where
they work, and if they have any work-related issues where they work.
|
by: striker |
last post by:
I have a comma delimited text file that has multiple instances of
multiple commas. Each file will contain approximatley 300 lines. For
example:
one, two, three,,,,four,five,,,,six
one, two, three,four,,,,,,,,,,eighteen, and so on.
There is one time when multiple commas are allowed. Just prior to the
letters ADMNSRC there should be one instance of 4 commas. (
,eight,,,,ADMNSRC,thirteen, ). The text ADMNSRC is NOT in the same
| |
by: Dado |
last post by:
I have a next situation with the textbox field:
A - B = C
1. How to fill the A fill with the data from my previous recordset ?
Can I do it with the expression builder ?
2. I want that every field I can edit or count, depends on what fileds I
input the value ?
|
by: MLH |
last post by:
MyString = "All men are created equal"
Debug.PrintLen(MyString)
Now that's easy. But how about just counting
the letter "e"? Or, if I were curious to know
how many commas were in the string. How
might one do this in a query?
Suppose a table had single string field with
100 records, each containg a sentence
|
by: Adrienne Boswell |
last post by:
Although this is a client side issue, I am also posting to asp.general
in case there is someway to do this only server side (which I would
prefer).
Here's my form:
<form method="post" action="<%=request.servervariables("Script_name")
%>"
<% for i - 0 to 4%>
Header: <input type="text" name="header" id="header<%=i%>"
|
by: Dooza |
last post by:
Using ASP/VB I need to remove unwanted commas from the end of a field
that will be use in an array. There are items in the field that are
comma separated, so I don't want to remove them, just the end ones,
could be anywhere up to 5 unwanted commas.
Any ideas?
Cheers,
Steve
|
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...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |