Listbox Character Count (1 Viewer)

Hatman64

New member
Local time
Yesterday, 21:23
Joined
Sep 24, 2020
Messages
5
I have a listbox filled using a query of names.
Is there any way to display the number of characters in the listbox OR the query itself?

Here's the scenario: I have a tbl_Names with a field Lname, and a YesNo field
When the query runs it will only include names that are not Checked. or =No
As I add new names I want the Listbox to update from the query to include those NEW names but only up to a certain number of characters.
Hence the need to count the characters. Not the number of names.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:23
Joined
Oct 29, 2018
Messages
21,453
Hi. Welcome to AWF!

Just to clarify, did you want the number of characters for the entire list or for each item?
 

Hatman64

New member
Local time
Yesterday, 21:23
Joined
Sep 24, 2020
Messages
5
Sorry about that.
The entire list
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:23
Joined
Oct 29, 2018
Messages
21,453
Sorry about that.
The entire list
Hi. Thanks for the clarification. I would prefer to go the query route. Can you please post the SQL statement for your query?
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 21:23
Joined
May 21, 2018
Messages
8,525
This worked for me going using the listbox. Although no idea what this does. I used len which means it is counting spaces as a character. If not then you need to read character by character.
Code:
Public Function GetCount(lst As Access.ListBox, Column As Integer) As Integer
  Dim row As Long
  Dim start As Long
  If lst.ColumnHeads Then start = 1
  For row = start To lst.ListCount - 1
    GetCount = GetCount + Len(Nz(lst.Column(Column, row)))
  Next row
End Function

Public Sub GetCounttext()
  Debug.Print GetCount(Forms("form1").Controls("list0"), 0)
End Sub
 

Hatman64

New member
Local time
Yesterday, 21:23
Joined
Sep 24, 2020
Messages
5
SELECT tbl_Names.[CustName], tbl_Names.Listed
FROM tbl_Names
WHERE (((tbl_Names.Listed)=No));
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:23
Joined
Oct 29, 2018
Messages
21,453
SELECT tbl_Names.[CustName], tbl_Names.Listed
FROM tbl_Names
WHERE (((tbl_Names.Listed)=No));
Hi. Thanks for that. Let's say the name of your Query is "Query1," what do you get with the following query?
SQL:
SELECT Sum(Len(CustName)) As Char1, Sum(Len(Listed)) As Char2 FROM Query1
(untested)
 

Hatman64

New member
Local time
Yesterday, 21:23
Joined
Sep 24, 2020
Messages
5
Thanks DBGuy!
That does it.
I don't need the count of the listed field. But that 1st part gives me what i want.
Cheers!
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:23
Joined
Oct 29, 2018
Messages
21,453
Thanks DBGuy!
That does it.
I don't need the **** of the listed field. But that 1st part gives me what i want.
Cheers!
Hi. Glad to hear you got what you wanted. @MajP and I were happy to assist. Good luck with your project.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 18:23
Joined
Oct 29, 2018
Messages
21,453
Sorry about the Mis-spelling of the word count. Didn’t mean to be offensive at all :)
Wow! I didn't even notice. I'll have to let the owner know. Thanks!
 

Users who are viewing this thread

Top Bottom