Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

".additem" use with Access combo/list boxes 1

Status
Not open for further replies.

sard0nicpan

Programmer
Dec 28, 2004
57
US
I have found that Access does not support the ".additem" method for their list and combo box controls. So instead, I have been using the "Microsoft Forms 2.0" controls for list and comboboxes when executing with ".additem". I'm curious whether there is a command like ".additem" for Access form controls which will fill the combo and listbox objects native to Access forms? I figure there must be, but I have not found it yet.

Thanks and regards to all,

Tony
 
.AddItem/.RemoveItem for combos and lists became available starting with xp (2002) version.

Roy-Vidar
 
Thanks Roy-Vidar,

. . . but alas, I am for now stuck with 2000. So I guess my question should be:

"Is there a way to fill combo and list controls in Access 2000 (analogous to '.additem' in vb), or am I stuck with using Ms Forms 2.0 controls for this?"

I mean, if I really needed/wanted to use the Access controls I could always create a table to populate my combo/listbox, but that seems a pretty roundabout way of doing things compared to the VB technique of simply using additem/removeitem. Anybody?

Just wondering . . .

Tony
 
You may play with the RowSource and the RowSourceType properties.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
How are ya sard0nicpan . . . . .

It sounds like you need a [blue]RowSourceType[/blue] of [purple]Value List[/purple]. With this type, the [purple]RowSource is a list of strings with semicolon delimiters.[/purple] Be aware though . . . . Value List is [purple]limited to 2K characters[/purple] (including semicolons), so you may have to consider that table for large line count . . .

By the way . . . . [blue]AddItem[/blue] is used for [blue]CommandBar Combbox[/blue] (combobox on toolbars), not for forms.

Calvin.gif
See Ya! . . . . . .
 
TheAceMan1, .AddItem and .RemoveItems are methods of native Access combos and listboxes (for forms) starting with version 2002. You need an upgrade;-)

See for instance How to fill a list box or a combo box with database object names or Adding items to combo boxes and list boxes programmatically in Access for verification.

Which can also be said with regards to .Rowsource for .ValueList, which in 2002+ versions has the limit of 32K, which one might say is a significant improvement;-)

Addressing the issue at hand, here's some samples, one using a callback function, which circumvents 2000 limitation (filling a list with filenames) one "ordinary" Nailing Your Files: List Files in a Folder

Wouldn't it be a possibility of using a table/query in stead? Rowsource of "select somefields from sometable"?

Roy-Vidar
 
Yes! . . . . I'm aware . . . .

Its just [blue]sard0nicpan[/blue] specifically asked about 2000 . . . ;-)

Calvin.gif
See Ya! . . . . . .
 
Sorry, maybe I did not give enough context. I'm doing the populating programmatically, doing a "Select" from an Access query for those groups to which a member belongs to (!GGNAME/GroupName). The code works just fine, I was just curious whether I could have done the same thing with the Access listbox control.

Oh, and Aceman, the control I used is from the OLE class: "Microsoft Forms 2.0 ListBox" (ActiveX name:ActiveXCtl46). Additem works for it . . . how do I know? Well I'm looking at a full listbox courtesy of the code below. Out of curiousity I took a look for the control you mentioned (CommandBar Combbox), but I don't seem to have it (Access 2000).

I guess, suffice to say, the way I did it was just fine--I was just a bit surprised that the Access 2000 list/combo box controls did not support the additem method.

Thanks for your input!
Tony

Code:
strSql = "Select * from qryIDENTITYGroup where UserName = '" & Forms!Play.USERNAME & "'"

Set db = CurrentDb
Set rs = db.OpenRecordset(strSql, dbOpenDynaset, dbSeeChanges)


With rs

Do Until .EOF

  GroupName = !GGNAME
  Me.GGNAME.AddItem GroupName
  .MoveNext

Loop

End With
 
With a native access ListBox:
ME!GGNAME.RowSource = "SELECT GGNAME FROM qryIDENTITYGroup WHERE UserName='" & Forms!Play!USERNAME & "'"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Roy-Vidar, AceMan, and PHV:

Thanks for your input! In the end, without an upgrade to '02 it seems that its best to use the controls I mentioned above (once again, note its working like it is with just a few lines of code . . . ).

On the other hand, if I really had to use the Access control, the table/query solution seems best. I agree I could Dim an array for the RowSource, but my listbox length would be variable; making it more work than its worth to do it that way . . . agreed?

PHV: Hey, I tried your suggestion but it erred out. Maybe I misunderstood, but I got the message "method not supported ..." What reference supports it?

Regards,
Tony
 
PHV said:
With a [highlight]native access[/highlight] ListBox
I assumed this new listbox will be named GGNAME.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV:

For some reason after I closed out, restarted and went back to it, your line of code worked!(?) Don't know why, but I'm not complaining.

Merci, gracias, grazi and thanks

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top