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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ACCESS ComboBox (Kombinationsfeld), HowTo Add Items 3

Status
Not open for further replies.

AMosmann

Programmer
May 27, 2003
82
DE
Hi, I have to program some forms using standard controls.
I work with Win2k and MS Office 2k
The problem I have is not to find any function to add a line to the combobox (Kontrollfeld), there is no Add or AddItem- function.
The microsoft help does everything but help.
Ist this a special control? And howto add items?
It is not related to any data table.

Thanx
[afro]


Greetings Andreas
 
There is no AddItem!

AddItem will fail!

And if I use

Me.kf.ItemData(0) there will be an error 424...
(must be an object...)

:-|


Greetings Andreas
 
These are all functions i could use ...

AfterUpdate (NF) DisplayWhen (NF)
AllowAutoCorrect Enabled (NF)
AutoExpand FontItalic
BackColor FontName
BackStyle FontSize
BeforeUpdate (NF) FontUnderline
Bezeichnungsausrichtung FontWeight
BezeichnungsfeldX ForeColor
BezeichnungsfeldY Format
BorderColor Height
BorderStyle HelpContextID (NF)
BorderWidth InputMask
BoundColumn InSelection (NF)
Column IsHyperlink
ColumnCount ItemData
ColumnHeads Left
ColumnWidths LimitToList
ControlSource ListRows
ControlTipText (NF) ListWidth
ControlType Locked (NF)
DecimalPlaces MitBezeichnungsfeld
DefaultValue (NF) MitDoppelpunkt


N-Z

Name RowSource
OnChange (NF) RowSourceType
OnClick (NF) ShortcutMenuBar
OnDblClick (NF) SpecialEffect
OnEnter (NF) StatusBarText (NF)
OnExit (NF) TabIndex (NF)
OnGotFocus (NF) TabStop (NF)
OnKeyDown (NF) Tag
OnKeyPress (NF) TextAlign
OnKeyUp (NF) Top
OnLostFocus (NF) ValidationRule (NF)
OnMouseDown (NF) ValidationText (NF)
OnMouseMove (NF) Visible
OnMouseUp (NF) Width
OnNotInList (NF)

what to do?
:cool:


Greetings Andreas
 
Hi Andreas,

I think you are using Access here, and the way to control Combobox contents is with the RowSourceType and RowSource properties, for example,

Code:
Me.kf.RowSourceType = "Value List"
Me.kf.RowSource = """first"";""second"";""third"""

You might also want to adjust other properties like ColumnCount, for example with two columns,

Code:
Me.kf.ColumnCount = 2
Me.kf.RowSourceType = "Value List"
Me.kf.RowSource = """row 1 col 1"";""row 1 col 2"";""row 2 col 1"";""row 2 col2"""


Enjoy,
Tony
 
Hi Andreas,

Access will use a differnt type of combobox control if you click on the standard combobox icon in the toolbox, and you are correct it does not have an AddItem method, it does however have other extra properties as Tony has pointed out.

You can hovever use the Standard VB combobox control on an Access form. To do this click on the ActiveX button on the toolbox and then scroll down until you find Microsoft Forms 2.0 ComboBox select it and then click on your form, and you should have a combobox that looks exactly the same as the previous one, but does have a AddItem Method.

Why there are two types I can only guess, I suppose the Access version does have extra properties to make it easier to bind it to a tables data. I just use which ever type is most appropriate, and as you do not seem to need to make the box data bound I would try using the Microsoft forms 2.0 version. It is certainly easier to additems to it as you do not need to pass a string containing all the items each time you need to add a new one.

anyway hope that helps

Matt
 
Thank you very much, was a great help.
I normally play VC++ and delphi, so I did not know that element.
Do you know a good helpfile, where I can find !useful! hints how to handle access objects? Now I have a problem to set an Option, cant set it..
[hourglass]


Greetings Andreas
 
Hi Matt,

I referenced this thread for someone else asking about additem in combos (thread705-584015) and they have come back saying there isn't an additem method. I have now tried it myself and agree. Can you give any more info about it please?

Enjoy,
Tony
 
Thx for your answer, I did it like you said and it worked fine. I don't know, what information you want to get.

I workwith Access 2000, Win 2000, the standard combobox of the ToolBox.

I want to init some of the controls I use in an init-procedure. So the problem was how to add lines to the combobox, and the problem still is, how to set option-fields.

My first problem is solved by your answer.
So please ask more special, 'cause I don't know, what to answer.
[spin2][flip][spineyes]


Greetings Andreas
 
Andreas - the question was directed at Mattdrinks, not yourself - re: the MS Forms 2.0 combobox having an Additem method

Rgds
Geoff
Si hoc legere scis, nimis eruditionis habes
Get the best answers to your questions - faq222-2244
 
Where is the ActiveX button? I clicked on More Controls and there is no Microsoft Forms 2.0 on the list.

How do I get AddItem to work?

thanks.

Barbola
Curlers do it between the sheets!
 
Oh wait. I found Microsoft Forms 2.0 Combobox on the list and I added it to my form, but when I go to use AddItem, it is not available as a selection.



Barbola
Curlers do it between the sheets!
 
Sorry everyone, I have been busy at work and have only just checked this thread again. I will and try and answer the questions raised.

Firstly Barbola,
You are correct after, you have typed the comboboxes (MS Forms 2.0 version) name and the . a list of methods and properties pops up and AddItem is still not there!

But if you press Enter you will see that additem is capitalised to AddItem (if you did not type it correctly to start with that is. By the way I find this a very useful indicator to see if a method maybe supported when using VB and VBA) so it seems to have be recognised and if you finish typing the line, so you have something like this
Code:
Private Sub cmdFill_Click()
    ComboBox1.AddItem "Apples"
End Sub
You should find it executes fine, if not get back to me.

Tony,
I am not sure exactly what sort of information you are after, but to get the help file for the MS Forms 2.0 Combo Control AddItem method hi-light AddItem and Press F1 for help, you should get the option of selecting either the Access or MS Forms 2.0 help file, select MS forms 2.0 and click the Help button, up should pop a help page on the AddItem method. If you do not get the option of which type to select make sure you have Microsoft Forms 2.0 Object Library select in references (Tools menu)

If you still can not get the help files (sometimes links are missing) open Excel and press Alt+F11 to get the VBA editor then add a user form and drop a combobox onto it, this is by default a MS Forms 2.0 version, you will find there a lot more properties listed for it when you use it within the Excel VBA design environment then there are in the Access VBA environment, but the ones I have tried all still seem to work fine.

I do not know why Access and Excel use different version of the combobox and I seem to remember that other controls are also subtlety different, also I do not know if the versions used in Word are different again (I rarely program in Word). Remember you can always add the control you are after by using the insert ActiveX Control from the Insert menu, as long as you know which library the control is in and where the file containing the library is located.

Also make sure if you are running the application on a different computer that it has the correct version of the required libraries. DLL library conflicts can be a real problem when deploying applications and for this reason I try use the smallest number of libraries and keep to using the most popular controls to avoid problems.

I always check the references before I start programming to see if all the libraries I need are selected, and I also use the object browser to find out information about the libraries. You can get the Object Browser to display by pressing F2 in the VBA environments (Same in Access and Excel!) and it is excellent when you are working with unfamiliar libraries or just can not find the property, method or event you are looking for.
I hope this answers some of you questions, if not get back to me,
Matt
 
Sorry everyone I did not check the other threads before posting my response.

The confusion seems to be because the Access VBA editor does not list all the Properties, Methods and Events of the MS Forms comboxbox. Try using the same control in Excel VBA (It is the default combo on the toolbox) and you'll see a more complete list of entries in the popup list.

Both references seem to point to the same file, so I am guessing that the difference must be in the programming of the two different VBA environments. Has anyone tried it in Word?
 
Hi Matt,

Thanks for all that. I'm not sure now what I did when I tried it before; I thought I had typed it in despite it not showing in the intellisense, and I thought I had run it and checked the dropdown list. Anyway, I have now tried it again and you are correct. Sorry for having troubled you.

Access comes from a different stable from Word and Excel and regularly works slightly differently. The Access box is very much geared to being tied to other Access objects which is not always what you want. Knowing you can use both types is good. Have a star for the Info.

Enjoy,
Tony
 
Matt,

It does not work. I get a compile error. I added a few references but it didn't help.

Thanks!
Barb E.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top