Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 20th, 2006, 01:02 PM
Authorized User
 
Join Date: Feb 2006
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Bob, I was able to get the code to work, almost. When executing it would output to a table and to a list box and included all of the combo box selections. But it will not count correctly. The only thing I changed in the code was the column names and the table as shown below.

strSQL = "SELECT CF1, CF2, CF3, CF4, CF5, CF6, CF7, CF8, CF9, CF10 FROM MainTable"

If the columns are populated like this with the rest of the fields blank:

MainTable
CF1 CF2 CF3 CF4 CF5 CF6
A B C D E F
G H I J K L
M N O P Q R
S T U V W X
Y Z AA BB CC DD

I would get this result:

tblOptionCounts
OptionName OptionCount
A 1
B 1
C 1
D 1
E 1
F 5
G 1
H 1
I 1
J 1
K 1
L 5
M 1
N 1
O 1
P 1
Q 1
R 5
S 1
T 1
U 1
V 1
W 1
X 5
Y 1
Z 1
AA 1
BB 1
CC 1
DD 5

The count should be 1 for all of them.
If I populate the table with one field fore each of the five records like this with the rest blank:

MainTable
CF1
A
B
C
D
E

I get this result:

tblOptionCounts
OptionName OptionCount
A 10
B 10
C 10
D 10
E 10

On Friday I read about indexes and collections and still do not have any idea of what I am doing wrong.

Scott
 
Old March 20th, 2006, 03:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Scott,

Should be a simple fix. We just gotta' exclude NULL values from the count. Here's the relevant modified code:

Code:
Do Until rstOriginalData.EOF
        For Each fld In rstOriginalData.Fields
            If Not IsNull(fld.Value) Then
                On Error Resume Next
                total = 0
                key = fld.Value
                total = OptionCounts(key)
                OptionCounts.Remove key
                OptionCounts.Add total + 1, key
                OptionNames.Add key, key
            End If
        Next fld
        rstOriginalData.MoveNext
    Loop
Let me know if that gets it for you.

Bob

 
Old March 20th, 2006, 03:49 PM
Authorized User
 
Join Date: Feb 2006
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That seems to do it. Thank you very much for your help.

Scott
 
Old March 20th, 2006, 03:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

You're welcome Scott. Glad that seemed to get it for you.

Bob






Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding identical values voskoue Access VBA 7 January 30th, 2007 08:43 AM
Counting Number of Rows Between Data Range eusanpe Excel VBA 6 September 21st, 2006 07:17 AM
finding "c# data security handbook" code gzfarmer C# 2 April 26th, 2006 03:32 AM
Finding values from duplicated nodes swwallace XSLT 1 March 2nd, 2006 05:21 AM
Finding , Locatin and Receiving data with XML. betzy XML 2 May 25th, 2004 07:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.