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 7439
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(StringIn 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 CountStringItems( _
Items As String, _
Delim As String _
) As Long
Dim varaItems As Variant
varaItems = Split(Items, Delim)
CountStringItems = ArrayCount(varaItems)
End Function
Public Function ArrayCount(varArray 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(StringIn 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(TextIn 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.com... Easiest way is to use the Split function:
Public Function CountStringItems( _ Items As String, _ Delim As String _ ) As Long Dim varaItems As Variant varaItems = Split(Items, Delim) CountStringItems = ArrayCount(varaItems) End Function
Public Function ArrayCount(varArray 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 =CountStringItems([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 CountStringItems( _ Items As String, _ Delim As String _ ) As Long Dim varaItems As Variant varaItems = Split(Items, Delim) CountStringItems = ArrayCount(varaItems) End Function
Public Function ArrayCount(varArray 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.com... 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 =CountStringItems([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 CountStringItems( _ Items As String, _ Delim As String _ ) As Long Dim varaItems As Variant varaItems = Split(Items, Delim) CountStringItems = ArrayCount(varaItems) End Function
Public Function ArrayCount(varArray 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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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....
|
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"...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |