Calling NotInList event code for multiple forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FireMedic
    New Member
    • Mar 2007
    • 17

    Calling NotInList event code for multiple forms

    Hello all,

    I am creating an application that has an equipment inventory and maintenance form that has numerous subforms that are displayed depending on the category of equipment selected.
    I have two common combo boxes on each subform - "Supplier" and "Manufactur er". I use the following code for the "NotInList" event and it works fine. (This is the version for the "Supplier" cbo)

    [I]
    Code:
    [I]Public Sub cboSupplier_NotInList(NewData As String, Response As Integer)
    On Error GoTo cboSupplier_NotInList_Err
        Dim intAnswer As Integer
        Dim strSQL As String
    
        intAnswer = MsgBox("The Supplier " & Chr(34) & NewData & _
            Chr(34) & " is not currently listed." & vbCrLf & _
            "Would you like to add it to the list now?" _
            , vbQuestion + vbYesNo, "I-TEAM Utilities")
        If intAnswer = vbYes Then
            strSQL = "INSERT INTO tbl_Suppliers([SupName]) " & _
                     "VALUES ('" & NewData & "');"
            DoCmd.SetWarnings False
            DoCmd.RunSQL strSQL
            DoCmd.SetWarnings True
            MsgBox "The new Supplier has been added to the list." & _
            " Please enter remaining contact information" & vbCrLf & _
            "before proceeding further" _
                , vbInformation, "I-TEAM Utilities"
            Response = acDataErrAdded
            DoCmd.OpenForm "frm_Test2"
        Else
            MsgBox "Please choose a Supplier from the list." _
                , vbInformation, "I-TEAM Utilities"
            Response = acDataErrContinue
        End If
    cboSupplier_NotInList_Exit:
        Exit Sub
    cboSupplier_NotInList_Err:
        MsgBox Err.Description, vbCritical, "Error"
        Resume cboSupplier_NotInList_Exit
    
    End Sub
    I would like to include these once as a public function or sub and call them with the NotInList event of each combo box but have had no success in getting this to work. The row source tables are the same for these cbo boxes on all 18 subforms.
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    I have never tried this, but you should be able to get it to work if you add the form object to the sub's arguments as shown. Also, give the sub a slightly different name (g = global) to distinguish from the form's not in list event, which will fire if the limit to list property is set to yes and the item entered is not on the list. Essentially all you are doing is passing the NotInList call from the local to central processing.
    Code:
    Public Sub gcboSupplier_NotInList(Frm As Form, NewData As String, Response As Integer)
    When the NotInList event is fired for the form, just call the public sub and pass the required parameters.
    Code:
    Private Sub cboSupplier_NotInList()
    gcboSupplier_NotInList(Me)
    
    End Sub

    Comment

    • FireMedic
      New Member
      • Mar 2007
      • 17

      #3
      You Sir are a prince among PuppyDogBuddies .

      Works like a charm.
      Thanks a million

      Comment

      Working...