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!

Add new record to ComboBox

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How do I let the user add a new record in a combobox. Say the item he typed is not in the list I want to give him the option of adding it. right now the computer doesn't let him and I would like to put a message box asking if he wants to add the record and if he answeres yes open the appropiate form.

Thanx
 
ComboBox.AddItem ValueOfItemNotOnList
Is this what you are looking for?
 
I want to tell the computer if the value is not in list then msgbox "Do you want to add this item?" if he says yes then i'll open the form to add item.
 
What I do is put in the list "Add new item". Then you check for this in the click event.

if combo1.text = "Add new item" then
form2.show
end if


David Paulson


 
Here's another way that doesn't require ny special additional entries in the combobox:

Option Explicit
Private Const CB_FINDSTRINGEXACT = &H158
Private Const CB_ERR = (-1)

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long



' Example uses KeyDown event, but you may wish to use something else
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then Call CheckEntry(Combo1)

End Sub



Private Sub CheckEntry(cboTest As ComboBox)
Dim result As Long
Dim strTest As String

strTest = cboTest 'use default value

If SendMessage(cboTest.hwnd, CB_FINDSTRINGEXACT, -1, strTest) = CB_ERR Then
' You can add your messagebox routine here
' For the sake of the example I merely add the new entry straightaway
cboTest.AddItem strTest
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top