Solved

need to know total number of items in the listbox and pass the value to an integer

Posted on 2006-10-25
13
262 Views
Last Modified: 2008-02-01
I am designing a Form application in Access 2003.

I have a listbox containing data populated on basis of a selection in a combo box. I need to pass the rowcount of the listbox to an integer variable for furthur process. my combo box contains Date, my list box returns customer names for a Date selected.

I thought about two different approaches, but not successful yet.

1. I want to Dim ListControl as Control, try to use ListCount.
2. I tried to use Dcount function which needs taking the value of selection of the combo box as criteria in the function. I can write a query as expression to get same records as those populated in the list box.
Dcount("customer", "qry", "orderdate = Form!frm_master!cbo_orderDate"), my problem is that my criteria code is not right.

Any ideas? Thanks
0
Comment
Question by:jc50967w
13 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 17804358
dim x
x=me.listboxname.listindex
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 17804361
dim x
x=me.listboxname.listcount
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
ID: 17804364
dim iCnt as integer

iCnt = Me.mylistbox.ListCount

msgbox "Number of items = " & iCnt
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 65

Expert Comment

by:Jim Horn
ID: 17804366
{no points please}

dim x as Integer
x=me.listboxname.listcount
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17804391
And using DCOUNT

If within the sama form, just do this

Dcount("customer", "qry", "orderdate = #" & Me.cbo_OrderDate & "#")

otherwise
Dcount("customer", "qry", "orderdate = #" & Form!frm_master!cbo_orderDate & "#")

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17804400
And yet summat else, which I forgot to post

If your combo has 3 columns say, selecting the value (bounded column) may not be the one u need
therefore u can specify what column u want

col 0 is 1st column of data
col 1 is 2nd, etc

Dcount("customer", "qry", "orderdate = #" & Me.cbo_OrderDate.Colum(0) & "#")
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17804411
U may perhaps need to wrap OrderDate with CDATE but I think u should be ok

Im off home now, see ya all
0
 

Author Comment

by:jc50967w
ID: 17804698
Rockiroads, my combo box only has one column. The filed name OrderDate is just example name I used to discribe in this case. My real database, tables and fields are with very complicated business concept, and hard to post them in few lines. Then I use customer and their order as example case in here.

Thank you everyone.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 17804772

as posted above

dim x
x=me.listboxname.listcount

is enough to get the number of items from the listbox

if you want to use dcount, try this

Dcount("customer", "qry", "cdate(format([orderdate],'mm/dd/yyy')) = #" & cdate(Format(Form!frm_master!cbo_orderDate,'mm/dd/yyy')) &"#"),
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 17804779
sorry

if you want to use dcount, try this

Dcount("customer", "qry", "cdate(format([orderdate],'mm/dd/yyyy')) = #" & cdate(Format(Form!frm_master!cbo_orderDate,'mm/dd/yyyy')) &"#")
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17806357
ok jc50967w, where are we at this

you now know how to get a listcount and Ive told you about the error you had in your dcount

I mentioned the multicolumn just in case, but its not a problem now since u only have the one column.
Did the correction to the DCOUNT work? (after u change it to your fields that is)

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now