Results 1 to 3 of 3

Thread: NotInList Event

  1. #1
    Join Date
    May 2004
    Posts
    63

    Unanswered: NotInList Event

    I have combo box based on one Field which is PK and i have use following code for the NotInList event of combo to add new data to the table. This code works fine since there is one field in table.

    Now i also have another combo box that is based on table which has 3 fields such as
    ID.....FName.......LName........How can i use this code to enter new data from combo box using NotInList event ?




    Code:
    Dim strsql As String, x As Integer 
    x = MsgBox("Do you want to add this value to the list?", vbYesNo)
    If x = vbYes Then
        strsql = "Insert Into tblClinics ([ClinicName]) values ('" & NewData & "')"
        'MsgBox strsql
        CurrentDb.Execute strsql, dbFailOnError
        Response = acDataErrAdded
    Else
        Response = acDataErrContinue
    End If

  2. #2
    Join Date
    Jun 2004
    Location
    Terrapin Nation
    Posts
    205
    You could try something like this:

    Dim db as DAO.database
    Dim rst as DAO.recordset

    set db = currentdb
    set rst = db.openrecordset("TableNameYouWantToInsertInto", dbopentable)

    With rst
    .addnew
    ![ID] = "Your value to insert for ID here"
    ![fname] = "Your value to insert for fname here"
    ![lname] = "Your value to insert for fname here"
    .update
    end with

    rst.close


    Just make sure the names of the fields in the brackets above are equal to your field names in the table you want to update. ANd of course "TableNameYouWantToInsertInto" = your table name.

  3. #3
    Join Date
    May 2004
    Posts
    159
    I was just doing the same thing with the notinlist event. I had a table with one field and it worked fine. I expanded it to 4 fields and it stopped working.
    I looked into it and found the problem was I made the id field the key which did not allow duplicates. It was not an autonumber field- I removed the key designation and it worked because the entry was comming in with the id field defaulting at 0. I had used the ID field to allow arranging in a custom order. One of the risks you run when you modify an existing table structure rather than designing one correctly from scratch.

Posting Permissions

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