Solved

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

Posted on 2006-10-25
13
272 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
[X]
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
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

733 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