Combo box add record

Posted on 2003-02-22
Medium Priority
Last Modified: 2010-05-01
i have a combo box that when an entry is selected it adds its contents as a new record to a table.  The problem i have is that if i scroll through the selection using the arrow keys it keeps adding every item the selection is currently on.

is there any way to only execute the code when the selection has been confirmed

i have tried the code on click and change.

the code is

Private Sub cmbAction_Change()
If Not (cmbAction.BoundText = "Select Action" Or cmbAction.BoundText = "") Then
AdodcTodo.Recordset!ID = AdodcCustomers.Recordset!ID
AdodcTodo.Recordset!Date = Date
AdodcTodo.Recordset!Operation = cmbAction.BoundText
AdodcTodo.Recordset!Completed = False
AdodcTodo.Recordset!Time = Now
End If
End Sub

any ideas thanks
Question by:Marcusw
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8001142
I would say to just put that code into a command button click event.  That way the user can keep under control what is added.  And I would also suggest having a message box pop up after each item is added so that the user is sure that it has been done.


Author Comment

ID: 8001184
thanks for the suggestion but it would be too easy for the user to forget to press the button.

I have to i it all happen at the same time
LVL 18

Accepted Solution

Sethi earned 200 total points
ID: 8001201
Use flags to achieve what you want. Here is the code:

Dim boolDontSave As Boolean

Private Sub Combo1_Click()
    If boolDontSave = False Then
        txtSubject = Combo1.Text
    End If
End Sub

Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
        boolDontSave = True
        boolDontSave = False
    End If
End Sub

Expert Comment

ID: 8002273
You could try the code in the lost focus event, it will only add a record when the user has made the selection and moved on to something else


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question