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

Calling NotInList Function

Status
Not open for further replies.

AmigoMobility

Technical User
May 8, 2005
57
0
0
US
I am using a function for the NotInList event on multiple cboBoxes. I can call the function from the forms module using: Response = NIL(NewData), however I would rather not put this call behind every cboBox and into the forms module. Is there a way to put this call into the property of the cboBox NotInList event instead?

TIA,
Shane
 
Not sure what you mean? Are you using the NotInList-event to call the function or not?

Pampers [afro]
Keeping it simple can be complicated
 
Hey Pampers,

Thanks for your reply. I am pasting the function and code that I am using to accomplish what I'm doing. Remember my goal is to prevent from having to enter Response = NIL(NewData) in each and every NotInList event of each and every cboBox.

Here's my code:
Code:
Function NIL(NewData As String) As Integer
    
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim stControlName As String
    Dim stLabelName As String
        stControlName = Screen.ActiveControl.Name
        stLabelName = Me.txtLabelName
    
    If Eval("Msgbox('The " & stLabelName & " ''" & NewData & "'', Is Not On The " & stLabelName & " List!@Would you like me to " & _
                    "add ''" & NewData & "'' to the current " & stLabelName & " List?" & _
                    "@@',4,'AMC Database System Error Message')") = vbNo Then
        Me.cboChair.Undo
        NIL = acDataErrContinue
        Exit Function
    Else
        Set db = CurrentDb
        Set rs = db.OpenRecordset("Component", dbOpenDynaset)
        On Error Resume Next
        rs.AddNew
            rs!Component = NewData
            rs!DiscrpID = Me.txtDiscripID
        rs.Update
        
        If Err Then
            MsgBox "An error occurred. Please try again."
            NIL = acDataErrContinue
        Else
            NIL = acDataErrAdded
            rs.Close
            Set rs = Nothing
            Set db = Nothing
        End If
        
    End If
    
End Function

Function ftxtFill()

    Dim strControlName As String
    strControlName = Screen.ActiveControl.Name
    
    Me.txtDiscripID = Mid(Forms![frmEvalTemplate](strControlName).Tag, InStr(Forms![frmEvalTemplate](strControlName).Tag, " ") + 1)
    Me.txtLabelName = Left(Forms![frmEvalTemplate](strControlName).Tag, InStr(Forms![frmEvalTemplate](strControlName).Tag, " "))
    
End Function

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

    Response = NIL(NewData)
    
End Sub
 
Ok, I get it. But it looks like a bit of a contradiction. You want to raise the NIL-event, but you don't want to put the code in for each combo.

Just a thought: If the putting of the code is too much work, you might want to think about automating putting the NIL-code. Like: go through all the form, check all the controls, and if control is a combobox then write the NIL-code in the module.

Pampers [afro]
Keeping it simple can be complicated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top