Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 137
  • Last Modified:

Combo box add record

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.AddNew
AdodcTodo.Recordset!ID = AdodcCustomers.Recordset!ID
AdodcTodo.Recordset!Date = Date
AdodcTodo.Recordset!Operation = cmbAction.BoundText
AdodcTodo.Recordset!Completed = False
AdodcTodo.Recordset!Time = Now
AdodcTodo.Recordset.Update
End If
End Sub


any ideas thanks
0
Marcusw
Asked:
Marcusw
1 Solution
 
JacamarCommented:
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.

Jacamar.
0
 
MarcuswAuthor Commented:
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
0
 
SethiCommented:
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
    Else
        boolDontSave = False
    End If
End Sub
0
 
Hornet241Commented:
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

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now