Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2002
    San Juan, Puerto Rico

    Unhappy Unanswered: How to add data to a combo box?

    I am working on a marketing program and I am trying to make that when the user is entering the data i have a combo box and want to add new data to that combo box with out going to the combo box data form.

    I've been trying this code that I found:

    After setting the Limit to List property to Yes, add the following code to the Not In List Event:

    TableName is the table where the data should be added
    FieldName is the field in which the data should be added

    Private Sub cboFieldName_NotInList(NewData As String, Response As Integer)
    Dim db As Database, rs As Recordset
    Dim strMsg As String
    strMsg = "'" & NewData & "' is not a current name in the list. "
    strMsg = strMsg & " Do you want to add it to the list?"
    strMsg = strMsg & "@Click Yes to add it or No to retype it."
    If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
    Response = acDataErrContinue
    Set db = CurrentDb
    Set rs = db.OpenRecordset("TableName", dbOpenDynaset)
    On Error Resume Next
    rs!FieldName = NewData

    If Err Then
    MsgBox "Error. Please try again."
    Response = acDataErrContinue
    Response = acDataErrAdded
    End If
    End If
    End Sub
    but i keep getting an error.

  2. #2
    Join Date
    Jul 2002
    1) When you post a message it helps to show the error!

    2) I'm assuming it's a reference error. Make sure you have a reference to the DAO library (Microsoft Data Access Objects 3.6), from the Tools -> References menu.

    There have been many posts made throughout the world.
    This was one of them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts