Results 1 to 2 of 2
  1. #1
    elinde is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    1

    NotInList event issue

    I'm using the code below to add a record to my Organizations table when the name typed in the Organization box on the Master form is Not in List.

    The Organization table only has two fields, the ContactID autonumber field and the the Organizations text field. The code opens frmOrganization, and it does insert a record into tblOrganizations with an ID and the correct new organization name. But it also inserts a a second record into the table with a new ID and the ID of the previous record as the organization name, and it it this record that is linked to the main table:

    ContactID Organization
    70 The X Company
    71 70

    The master table ends up with 71 in the organization link field, when it should be 70 and the second row shouldn't even exist. Below is the code, lifted from Microsoft:

    Dim Result
    Dim Msg As String
    Dim CR As String

    CR = Chr$(13)

    ' Exit this subroutine if the combo box was cleared.
    If NewData = "" Then Exit Sub

    ' Ask the user if he or she wishes to add the new customer.
    Msg = "'" & NewData & "' is not in the list." & CR & CR
    Msg = Msg & "Do you want to add it?"
    If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
    ' If the user chose Yes, start the Customers form in data entry
    ' mode as a dialog form, passing the new company name in
    ' NewData to the OpenForm method's OpenArgs argument. The
    ' OpenArgs argument is used in Customer form's Form_Load event
    ' procedure.
    DoCmd.OpenForm "frmOrganizations", , , , acAdd, acDialog, NewData
    End If

    ' Look for the customer the user created in the Customers form.
    'Result = DLookup("[Organization]='" & NewData & "'")
    Me.Organization = DLookup("[ContactID]", "tblOrganizations", _
    "[Organization]='" & NewData & "'")

    If IsNull(Result) Then
    ' If the customer was not created, set the Response argument
    ' to suppress an error message and undo changes.


    Response = acDataErrContinue
    ' Display a customized message.
    MsgBox "Please try again!"
    Else
    ' If the customer was created, set the Response argument to
    ' indicate that new data is being added.
    Response = acDataErrAdded
    End If

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I would look at the code in the frmOrganizations form that uses the OpenArgs value. This code looks okay.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 02-09-2011, 07:43 AM
  2. Cancelling the NotInList event
    By Remster in forum Programming
    Replies: 12
    Last Post: 11-21-2010, 10:12 AM
  3. NotInList with Many to Many
    By SAC in forum Programming
    Replies: 17
    Last Post: 11-21-2010, 06:42 AM
  4. Replies: 0
    Last Post: 10-12-2010, 06:08 AM
  5. Troubleshoot NotInList Event Procedure
    By skyrise in forum Programming
    Replies: 4
    Last Post: 02-23-2009, 06:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums