Full Version: Supress default error message
UtterAccess Forums > Microsoft® Access > Access Forms
peakcomp
I am using the 'On Not in List' event to execute the code below from a ComboBox
CODE
Private Sub RespPerson_NotInList(NewData As String, Response As Integer)
Dim i As Integer
Dim Msg As String
Dim stDocName As String
sg = "'" & NewData & "' does not exist as you entered." & vbCr & vbCr
Msg = Msg & "Would you like to search the Team list?"
O= MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Team Member")
If i = vbYes Then
stDocName = "frmTeamLookup"
DoCmd.OpenForm stDocName, , acDialog
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub

The code does what I want it to do but a message appears with 'The text you entered isn't an item in the list' with an OK button.
How can I hide/suppress/bury/expunge/prevent this message from appearing?
Thanks for looking
theDBguy
Are you actually trying to add the new person to the rowsource of the combobox? If so, why would the user have to search in another form? It seems that this new person already exists somewhere else, and if that's the case, why not just use that source as the row source for the combobox?
peakcomp
The client has requested that when a name doesn't exist to have them search the existing list of Team members (in frmTeamLookup) rather than just adding a new team member. If they cannot find the record after searching, then they can create a new one.
There is also a flag in the Team Members table that makes a person inactive and the combobox filters for only active. So in that case, the record needs to be set as active to be used rather than creating a new record.
theDBguy
My question then is, why is the rowsource for the combobox different from the recordsource of the form frmTeamLookup?
peakcomp
Not sure if I am answering your question correctly but here goes.
The combobox on frmProjectEdit gets its values by looking up names from tblTeam and displaying them in the cbo as last, first. To keep the list shorter, it filters out anyone that is not flagged as 'active'.
If the name is in the list, it stores the ID from tblTeam as the value in tblProject for the RespPerson.
If the name is not in the list, I need to send them to another form that will allow them to look up the person to see if they exist before creating a new Team record.
theDBguy
Thanks, I believe you did answer my question, and it's a little clearer to me now. In light of this new information, I have two other questions:
. If the person was found in the lookup form, are you setting their flag back to active?
2. Are you using the same lookup form to add a new person if the one entered in the combobox was not found?
The problem with the error message you're talking about, I think, is that the rowsource of the combobox is not being updated properly when the control is returned back to the original form. You'll have to step through the process of looking up the new name and make sure that it is actually added to the combobox, either by resetting the active flag or adding the name as a new record.
HTH
peakcomp
1. If the person was found in the lookup form, are you setting their flag back to active?
The persons status can be changed manually to active from the lookup form by checking the y/n box
. Are you using the same lookup form to add a new person if the one entered in the combobox was not found?
The lookup form has a button at the bottom to add a new team member. The lookup form is used for more than just locating and adding team members missing from the combobox. It can be accessed directly from the nav form to allow users to look someone up and see what projects they are currently associated with
So is the error I am seeing a byproduct of using the On Not in List event and trying to break its usual routine?
theDBguy
Thanks for answering my questions, that helps a lot.
Yes, I believe that is correct. When you type a name that is not on the list and activate the record from the lookup form, do you still get the default error?
If you're still having problems, you can post a small copy of your db, and I can try to help you figure it out.
peakcomp
'The text you entered isn't an item in the list'
oes anyone have a way to suppress the On Not in List error message listed above?
My code (below) works as I want it to, just have this pesky message that interrupts the process.
CODE
Private Sub cboRequestor_NotInList(NewData As String, Response As Integer)
Dim i As Integer
Dim Msg As String
Dim stDocName As String
Msg = "'" & NewData & "' does not exist as you entered." & vbCr & vbCr
Msg = Msg & "Would you like to search the Team list?"
O= MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Requestor")
If i = vbYes Then
[cboRequestor] = 1
stDocName = "frmTeamLookup"
DoCmd.OpenForm stDocName, , acDialog
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.