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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add a value to listbox 1

Status
Not open for further replies.

Seeff

Programmer
Dec 2, 2002
33
IL
I have a listbox on a form with some type values. One of the values is "other" i.e. add a new type.
I manage to get access to display a new text box into which the user then populates with a new value. How do I get the new value to be (1) shown in the list (2)permanently added to the list? Thanks!
 
Hi

If you populate the list from a table, or a query based onm a table, then just add the new item to the table, and requery the listbox Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Seeff, I use combo boxes rather than list boxes and allow the user to add an item that's not already in the database. Here's the code I have behind a combo box where the user tries to add a new vendor on a purchase order form. It opens a dialog box in data entry view.

Private Sub cboVendorID_NotInList(NewData As String, Response As Integer)

Dim intNewVendor As Integer, intTruncateName As Integer, _
strMsgBoxCaption As String, intMsgDialog As Integer

strMsgBoxCaption = "Vendor Not In List"
intMsgDialog = vbYesNo + vbQuestion + vbDefaultButton1
intNewVendor = MsgBox("Do you want to add a new vendor?", intMsgDialog, _
strMsgBoxCaption)

If intNewVendor = vbYes Then
' Remove vendor from the Vendor combo box so control can be requeried
' when user returns to form.

DoCmd.RunCommand acCmdUndo



' Open AddNewVendor form.
DoCmd.OpenForm "frmVendors", acNormal, , , acAdd, acDialog, _
NewData

'Continue without displaying default error message and add new value
'to the combo box.

Response = acDataErrAdded

End If

End Sub


If you're not concerned about the new data showing up in the combo box immediately (i.e., you just want the user to be able to enter new data) you might do something like this. (Here's where I let a user enter a new customer (e.g., contact) on a work order.

Private Sub ContactID_NotInList(NewData As String, Response As Integer)
On Error GoTo HandleErr

If MsgBox("Would you like to add this contact to the database?", _
vbYesNo + vbQuestion, "Contact not in JSJ database") = vbYes Then
Response = AddToList("Contacts", "ContactName", NewData)
Else
Response = acDataErrDisplay
End If


ExitHere:
Exit Sub

HandleErr:
Select Case Err
Case Else
MsgBox Err & ": " & Err.Description, , _
"Form_frmWorkOrder.ContactID_NotInList"
End Select
Resume ExitHere
Resume

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top