473,406 Members | 2,345 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,406 software developers and data experts.

Help on Updating Combo Box

29
Hi -

I have a combo box in a form from a table called 'client names'. I would like users to be able to select name and also add a new name to the combo box, which would also add to the table 'clients name'.

What I have now, is user only able to select a name from combo box but not add unless they exit form and add to table.

Can't seem to figure this one out.

Thanks!
Dec 5 '06 #1
7 1353
NeoPa
32,556 Expert Mod 16PB
Unfortunately, this is not possible in a ComboBox.
A ListBox can have an item entered which is not in the current list but I don't think you can trigger an addition to any table that way.
What I think you need is a form structure for adding your record. Possibly selected (filtered) by your ComboBox entry.
Dec 5 '06 #2
ADezii
8,834 Expert 8TB
Hi -

I have a combo box in a form from a table called 'client names'. I would like users to be able to select name and also add a new name to the combo box, which would also add to the table 'clients name'.

What I have now, is user only able to select a name from combo box but not add unless they exit form and add to table.

Can't seem to figure this one out.

Thanks!
'It is a rather unorthodox approach, but if you are still interested this will
'definately work. Crerate a Command Button next to the Combo Box and
'duplicate this code in the Click() Event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddNameToComboBox_Click()
  2. On Error GoTo Err_cmdAddNameToComboBox_Click
  3.  
  4. Dim strNameToAdd As String
  5.  
  6. strNameToAdd = InputBox$("Name to Add", "Add Name To Combo Box")
  7. If Len(strNameToAdd) > 0 Then
  8.   Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  9.   Set MyDB = CurrentDb()
  10.   Set MyRS = MyDB.OpenRecordset("Client Names", dbOpenDynaset)
  11.     MyRS.AddNew
  12.       MyRS![Name] = strNameToAdd
  13.     MyRS.Update
  14.     MyRS.Close
  15. End If
  16.  
  17. Me![cboName].Requery
  18.  
  19. Exit_cmdAddNameToComboBox_Click:
  20.     Exit Sub
  21.  
  22. Err_cmdAddNameToComboBox_Click:
  23.     MsgBox Err.Description, vbExclamation, "Error in cmdAddNameToComboBox()"
  24.     Resume Exit_cmdAddNameToComboBox_Click
  25. End Sub
NOTE: Should you need any further clarification, please let me know...
Dec 5 '06 #3
1. Create a cmdAdd button next to the combo box.
2. Make a AddAClient Form (Pop up form) so that user can add a new client. At the bottom of the form, create a cmdSave button and a cmdCancel button. Whent he user click on the cmdAdd button, it should open the form AddAClient Form. After the user enter the data, when the user click on the cmdSave button, it should save to your Client table. Make sure to put code on all your cmd button.
3. In the combox box, After Update command, but code comboboxName.Requery.
It should update your combo box.
good luck!
Dec 5 '06 #4
rgsw
29
'It is a rather unorthodox approach, but if you are still interested this will
'definately work. Crerate a Command Button next to the Combo Box and
'duplicate this code in the Click() Event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddNameToComboBox_Click()
  2. On Error GoTo Err_cmdAddNameToComboBox_Click
  3.  
  4. Dim strNameToAdd As String
  5.  
  6. strNameToAdd = InputBox$("Name to Add", "Add Name To Combo Box")
  7. If Len(strNameToAdd) > 0 Then
  8.   Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  9.   Set MyDB = CurrentDb()
  10.   Set MyRS = MyDB.OpenRecordset("Client Names", dbOpenDynaset)
  11.     MyRS.AddNew
  12.       MyRS![Name] = strNameToAdd
  13.     MyRS.Update
  14.     MyRS.Close
  15. End If
  16.  
  17. Me![cboName].Requery
  18.  
  19. Exit_cmdAddNameToComboBox_Click:
  20.     Exit Sub
  21.  
  22. Err_cmdAddNameToComboBox_Click:
  23.     MsgBox Err.Description, vbExclamation, "Error in cmdAddNameToComboBox()"
  24.     Resume Exit_cmdAddNameToComboBox_Click
  25. End Sub
NOTE: Should you need any further clarification, please let me know...
Thanks for your reply. Being new to Access, I'm not sure what the code means. So when I did type in new name it gives me an error message that says "item not found in this collection". Did not add to Combo box or table.
Dec 5 '06 #5
MSeda
159 Expert 100+
Combo boxes also have an "on not in list" event that the above suggested technique can be used in.
Dec 5 '06 #6
NeoPa
32,556 Expert Mod 16PB
Combo boxes also have an "on not in list" event that the above suggested technique can be used in.
That's interesting. I didn't know that.
Dec 6 '06 #7
rgsw
29
Thanks for the suggestions, will give them all a try and see which works best for the form.
Dec 6 '06 #8

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

Similar topics

5
by: MARK | last post by:
Hi, I have a printer consumables database. I have a form designed to change the status of consumables ie. in use, dead, stock etc. I select one of my consumables records from the combo box...
15
by: Colin | last post by:
I have a query that calculates the selling price of products on customer orders. Selling prices are calculated based on the average cost of the items when purchased. As I make new purchases, the...
0
by: N. Graves | last post by:
I have not been successful with updating a query for a sub form of a tab control of a sub form of a form. Basically I have a form that has a combo box to select an equipment record and on this...
5
by: J. Yuan | last post by:
Hi, I am working on a checkout/inventory system. How can I make a button that when pressed, would update the previous fields transaction number to a table (for example, -3 printers, so that...
15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
0
by: Cndla | last post by:
hi, I have two combo boxes in a form. Functionality is such that selecting a value from the first combo box changes the value in the second combo box. Now this works fine in a normal computer with...
4
by: froglog | last post by:
I have created a MS access DB to track transport costs for tax purposes. I enter data into a main form that tracks miles traveled by date with a subform . The subform has fields for the date...
5
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
0
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
9
by: Marianne160 | last post by:
Hi, I know there are various answers to this problem available on the web but none of them seem to work for me. I am using Access 2003 to make a form to look up data from a table. I have so far...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.