Filling listbox from VBA

gazsharpe101

Registered User.
Local time
Today, 11:22
Joined
Oct 23, 2007
Messages
47
Hi, I am using MS Access 2003 and I wish to simply fill a listbox from VBA. I have read that you can just do listname.additem .... but I do not have the .additem option after inputting the list name and was wondering why this is? I believe it may just be a reference/component thing but I've no idea really :-)

Thanks,
Gareth.
 
Are you telling it where the list box is located:

me.myListBoxName.AddItem

???
ken
 
Hi, thanks for your reply. Yes I put me.listname before trying to use the additem feature but it still doesn't work.

Thanks again.
Gareth.
 
Can you post your exact code and what event you're trying to run it from?
 
The listbox is on a report, and the report is based on a query. All I want is for the listbox to be filled when the report is activated. I just want it to filter results from a query and put values into the listbox.

Thanks.
Gareth.
 
I would say to start with that I think a subreport would work better here...
 
I haven't got a problem with getting the data that I need really, it is literally just getting the .additem function onto VBA. I can't understand why it isn't there. If it would appear if I were to create a subreport then that is they way that I will go.

Thanks.
Gareth.
 
1 - You still haven't said what event you were trying
2 - Can't you simply set the listbox rowsource in design?
 
Hi,

1) I am trying to fill the listbox on the activation of the report, although it doesn't really matter when it gets filled to be honst as long as it is on the report.

2) I have tried setting the listbox rowsource in design view but it doesn't work because the report is based on a particular paramaterised query. What I need it to do to fill the listbox is effectively run the query again (or filter the query data) to get some specific data out of the query and put it into the listbox. As such, I am going to pass a value as the parameter for the query to be re-run, which I am doing through VBA and it is after that when I want the listbox to be filled.

Hope that makes sense.

Thanks.
Gareth.
 
Hum - I see now that it isn't an option. Back up and punt... :)
 
Exactly, I feel like banging my head against the desk! :rolleyes:

I don't know why the additem feature isn't available for me already, and neither is the .rowsourcetype or anything.
 
Apparently Additem method is not available in/on reports. forms only!
 
i thought that in order to use relational databases, combo and list boxes are filled from queries, and cannot be loaded directly with additems in the way you are trying to do

you can use a call-back function to fill a list box, but its sopmewhat tricky.

can't you get a query with the the items you need in the list box
 
Hi Gareth,

That property is not in the standard listbox. It is avialable in VB6 and 2005 but not Access.

If you want to use AddItem, it available in one of the ActiveX (MicroSoft Windows Common Controls-2 6.0 (SP4) or MicroSoft Windows Common Controls 6.0 (SP4) where you can use it.

If you have referenced this ActiveX controls and used it in a form, the property will appear in the standard listbox but you'll not be able to use this property.

Hi, I am using MS Access 2003 and I wish to simply fill a listbox from VBA. I have read that you can just do listname.additem .... but I do not have the .additem option after inputting the list name and was wondering why this is? I believe it may just be a reference/component thing but I've no idea really :-)

Thanks,
Gareth.
 
The Solution i used:

Reminds me. A while ago i faked a report and created a white form with all the controls i needed. When printed it looked just like a report.

Perhaps the solution to your answer?
 

Users who are viewing this thread

Back
Top Bottom