Solved

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

Posted on 2006-10-25
13
244 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 119

Expert Comment

by:Rey Obrero
Comment Utility
dim x
x=me.listboxname.listindex
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
dim x
x=me.listboxname.listcount
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
Comment Utility
dim iCnt as integer

iCnt = Me.mylistbox.ListCount

msgbox "Number of items = " & iCnt
0
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
{no points please}

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

Expert Comment

by:rockiroads
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
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
Comment Utility
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
Comment Utility
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 119

Expert Comment

by:Rey Obrero
Comment Utility

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 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 250 total points
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

771 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

10 Experts available now in Live!

Get 1:1 Help Now