Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2006-10-25
13
269 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

828 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