473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Add items to a combo box

35
I have a combo box that I would like to be able add items to in the back end VB, but

With Forms!search!search
.Visible = True
.additem "Application"
End With

gives me a runtime error 438 on the add item line.

Can anyone point me in the right direction please?
Aug 21 '07 #1
20 41810
FishVal
2,653 Expert 2GB
I have a combo box that I would like to be able add items to in the back end VB, but

With Forms!search!search
.Visible = True
.additem "Application"
End With

gives me a runtime error 438 on the add item line.

Can anyone point me in the right direction please?
Hi, istya.

AddItem method could not be invoked on Combobox which RecordSourceType is set to Table/Query. Is this your case?
Aug 21 '07 #2
istya
35
Hi, istya.

AddItem method could not be invoked on Combobox which RecordSourceType is set to Table/Query. Is this your case?
It's a blank combo box that is not connected to any recordsets or table/queries and the RecordSourcetype is set to value list.
Aug 21 '07 #3
FishVal
2,653 Expert 2GB
It's a blank combo box that is not connected to any recordsets or table/queries and the RecordSourcetype is set to value list.
"Object doesn't support this property or method."
Are you sure Forms!search!search returns you Combobox? Insert the following code
Expand|Select|Wrap|Line Numbers
  1.  Debug.Print TypeName(Forms!search!search)
before .AddItem or run it in immediate pane when execution stops on error.
Aug 21 '07 #4
istya
35
"Object doesn't support this property or method."
Are you sure Forms!search!search returns you Combobox? Insert the following code
Expand|Select|Wrap|Line Numbers
  1.  Debug.Print TypeName(Forms!search!search)
before .AddItem or run it in immediate pane when execution stops on error.
That gives me "Invalid use of Null"

This is beginning to drive me nuts!!
Aug 21 '07 #5
istya
35
That gives me "Invalid use of Null"

This is beginning to drive me nuts!!
Now it doesn't give me anything when I run the code.
Aug 21 '07 #6
FishVal
2,653 Expert 2GB
Now it doesn't give me anything when I run the code.
What does it mean ???
What does it send to VBA immediate window?
Put this code before With Forms!.... line.
Aug 21 '07 #7
missinglinq
3,532 Expert 2GB


AddItem is one of those methods that changes functionality from VB6 to VBA! In Access VBA, it only adds a list item to command bar combo boxes! It has no effect on a free-standing combobox that is part of a form!

Linq ;0)>
Aug 21 '07 #8
FishVal
2,653 Expert 2GB

AddItem is one of those methods that changes functionality from VB6 to VBA! In Access VBA, it only adds a list item to command bar combo boxes! It has no effect on a free-standing combobox that is part of a form!

Linq ;0)>
Sorry, Link.
It is simply not so. I've tested this just now. Additem works fine on free-standing combobox that is part of a form. Maybe you mean combobox with RowSource set to Table/Query.
Aug 21 '07 #9
istya
35
I've got it!!

I don't want additem, I want .recordsource = "val1;val2;val3"

Thanks you for the help
Aug 22 '07 #10
missinglinq
3,532 Expert 2GB
FishVAl: You're the first person I've heard make this claim, and I've seen this question asked literally dozens of times. I'd like to see your code for this.

From ACC2000 Help:

AddItem Method:
Adds a list item to the specified command bar combo box control.

Linq ;0)>
Aug 22 '07 #11
FishVal
2,653 Expert 2GB
FishVAl: You're the first person I've heard make this claim, and I've seen this question asked literally dozens of times. I'd like to see your code for this.

From ACC2000 Help:

AddItem Method:
Adds a list item to the specified command bar combo box control.

Linq ;0)>
Hi, Linq. Here it.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo0_DblClick(Cancel As Integer)
  2.     Me.Combo0.AddItem "qqq"
  3. End Sub
  4.  
[Combo0] - unbound combobox with RowSourceType="Value List"

AddItem is a method of Access.Combobox class (see in object browser).

Regards,

Fish
Aug 22 '07 #12
missinglinq
3,532 Expert 2GB
OK, Fish: Made a form, placed a combobox on it. Name is Combo0.
RowSourceType="Value List"
Placed this code in the DoubleClick event of the combobox
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Combo0_DblClick(Cancel As Integer)
  2.      Me.Combo0.AddItem "qqq"
  3.  End Sub
  4.  
Double-clicked on the combobox and I get the error:

"Method or Data Member Not Found"

and AddItem is hilited in code. What am I doing wrong? We are talking VBA here, not VB6, right?

Linq
Aug 22 '07 #13
istya
35
OK, Fish: Made a form, placed a combobox on it. Name is Combo0.
RowSourceType="Value List"
Placed this code in the DoubleClick event of the combobox
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Combo0_DblClick(Cancel As Integer)
  2.      Me.Combo0.AddItem "qqq"
  3.  End Sub
  4.  
Double-clicked on the combobox and I get the error:

"Method or Data Member Not Found"

and AddItem is hilited in code. What am I doing wrong? We are talking VBA here, not VB6, right?

Linq
I thought I was going mad when mine did that! I'm pleased it wasn't just me.
Aug 22 '07 #14
missinglinq
3,532 Expert 2GB
Fish, what version of Access are you running and what references are loaded?

Linq ;0)>
Aug 22 '07 #15
FishVal
2,653 Expert 2GB
OK, Fish: Made a form, placed a combobox on it. Name is Combo0.
RowSourceType="Value List"
Placed this code in the DoubleClick event of the combobox
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Combo0_DblClick(Cancel As Integer)
  2.      Me.Combo0.AddItem "qqq"
  3.  End Sub
  4.  
Double-clicked on the combobox and I get the error:

"Method or Data Member Not Found"

and AddItem is hilited in code. What am I doing wrong? We are talking VBA here, not VB6, right?

Linq
Oh, yes.

We are talking about VBA, Access2003, WinXP SP2.
Combobox: Access.Combobox, unbound, RowSourceType="Value List"
I hope you mean particulary Access.Combobox, not e.g. MSForms.Combobox.
And I hope you don't think that I gave an example w/o having tested it first.


AddItem Method
Adds a new item to the list of values displayed by the specified list box control or combo box control.

expression.AddItem(Item, Index)
expression Required. An expression that returns one of the objects in the Applies To list.

Item Required String. The display text for the new item.

Index Optional Variant. The position of the item in the list. If this argument is omitted, the item is added to the end of the list.

Remarks
The RowSourceType property of the specified control must be set to "Value List".

This method is only valid for list box or combo box controls on forms.

List item numbers start from zero. If the value of the Index argument doesn't correspond to an existing item number, an error occurs.

For multiple-column lists, use semicolons to delimit the strings for each column (for example, "1010;red;large" for a three-column list). If the Item argument contains fewer strings than columns in the control, items will be added starting with the left-most column. If the Item argument contains more strings than columns in the control, the extra strings are ignored.

Use the RemoveItem method to remove items from the list of values.

Example
This example adds an item to the end of the list in a list box control. For the function to work, you must pass it a ListBox object representing a list box control on a form and a String value representing the text of the item to be added.

Expand|Select|Wrap|Line Numbers
  1. Function AddItemToEnd(ctrlListBox As ListBox, _
  2.         ByVal strItem As String)
  3.  
  4.     ctrlListBox.AddItem Item:=strItem
  5.  
  6. End Function
  7.  
This example adds an item to the beginning of the list in a combo box control. For the function to work, you must pass it a ComboBox object representing a combo box control on a form and a String value representing the text of the item to be added.

Expand|Select|Wrap|Line Numbers
  1. Function AddItemToBeginning(ctrlComboBox As ComboBox, _
  2.         ByVal strItem As String)
  3.  
  4.     ctrlComboBox.AddItem Item:=strItem, Index:=0
  5.  
  6. End Function
  7.  
Aug 22 '07 #16
missinglinq
3,532 Expert 2GB
Yes, I'm talking about the plain old, gardern variety, Access Combobox , dragged down from the controls toolbar, not an ActixeX control. And no, I don't think you'd give an example w/o having tested it first, unless you qualified it by saying that it was untested! That's why I'm trying to figure out what's different about your setup and that of mine, the OP and a whole bunch of people over the years that get the same error ! What libraries are referenced in your setup?

Linq ;0)>
Aug 22 '07 #17
FishVal
2,653 Expert 2GB
Yes, I'm talking about the plain old, gardern variety, Access Combobox , dragged down from the controls toolbar, not an ActixeX control. And no, I don't think you'd give an example w/o having tested it first, unless you qualified it by saying that it was untested! That's why I'm trying to figure out what's different about your setup and that of mine, the OP and a whole bunch of people over the years that get the same error ! What libraries are referenced in your setup?

Linq ;0)>
I try to figure it to. Plz post your system config, Acc version etc.
And, G..d save us, plz look at Object Browser whether you have Access.Combobox.AddItem method.

What libraries are referenced in your setup?
Just those that are referenced by default.
  • VBA
  • Access 11.0 Object Library (here Combobox class defined)
  • DAO 3.6 Object Library
  • ADO 2.1 Object Library
  • OLE Automation

Regards,

Fish

P.S. Adding my example to the post.
Aug 22 '07 #18
Scott Price
1,384 Expert 1GB
My handy-dandy desk reference says this about AddItem:

Expand|Select|Wrap|Line Numbers
  1. Access 2002 finally added the AddItem method of Visual Basic list and combo boxes for populating these controls with VBA code.
Looks like if you're running Access 2000 you're out of luck with this method :-(

I think, Linq you are running 2000, no?

Regards,
Scott

p.s. I'm running Access 2003, and it works fine for me... Think Fish is running 2003 also?
Aug 22 '07 #19
missinglinq
3,532 Expert 2GB
Give that man (Scott) a cigar! Yes, indeed , Fish is running 2003 and I, sad to say, am running 2000! I'll put this little tidbit in my answers reference library!

This is one of those times (and there are a number of them) when you truly have to wonder, what in the world was Micro$oft thinking about? Why take an existing function and limit its application in VBA?

Happy hump day to all!

Linq ;0)>
Aug 22 '07 #20
missinglinq
3,532 Expert 2GB
There are only two (that I've ever been able to find) options for this problem for those running pre-ACC2002 versions, where .AddItem isn't available. The first, as istya has found out, I think, is that you can use a hack something like
Expand|Select|Wrap|Line Numbers
  1. YourComboBox.RowSource = YourComboBox.RowSource & ";" &  Me.ItemToAdd
Where ItemToAdd is a textbox where you enter a new item to be added. The problem with this method is that the items are only added to the RowSource for the duration of the Access session; once the form is closed the added items disappear.

The only way to permanently add items to the combobox is to base it on a small table designed for the sole purpose of populating the combobox. Then you can use a standard NotInList routine to add an item to the underlying table.

I've been trying to find a workaround that adds the item permanently without having to have a separate table for a while now, and will continue to look. Any ideas are welcome.

Linq ;0)>
Aug 23 '07 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nikolay Petrov | last post by:
I have asked a question before some time, and a guy responded to it. His answer raised new questions and I replied them back, but still no answer. I need them urgently so I am to post the whole...
2
by: http://www.visual-basic-data-mining.net/forum | last post by:
Hi... Say i have this string call "data" in Form1, this string contains number "5" value.... how do i pass this string to the Form2 and compare with the combo box items... The combo box ...
2
by: Robert | last post by:
Am using a nested continuous bound subform to add multiple records to the underlying table. One of the fields is based on a limit to list combo box. Any suggestions on best way to progressively...
0
by: Bharathi Kumar | last post by:
Hi, Iam working on a window application using .NET framework 2.0. I want a check box + some text in a combobox. User can select multiple items in combo box by using the check box.
1
by: Gian Paolo | last post by:
hi all i'm looking for a way to add 2 items in a combobox in the same line and hide one. i'm working on the code above but it returns me only the last value i entered and i do not know why.... ...
2
by: Dave | last post by:
>From a combo box the user can select a supplier. They then click the order button and are then taken to the orders page. From here comes the problem, I want the user to select a combo box unique...
6
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help with a combo box and this same code works on my first tab with a combo box. The error or problem i have is this code causes an index out of range error when i run it on my second combo...
2
by: mygirl22 | last post by:
Hi, I used this code to created 2 combo boxes General and Specific...and Only show Specific (Combo B) when Combo A is chosen..... What i need now is to know how to assign specific values to the...
0
by: Gordon Padwick | last post by:
A form contains controls, one or more of which can be other forms. A form that contains another form is known as a main form. A form contained by a main form is known as a subform. A subform itself...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.