Not In List Error Handling

  • Thread starter Thread starter scott
  • Start date Start date
S

scott

I'm using a MsgBox in a combo control's NotInList event to give the user a
choice to add a new combo entry. It works fine except when the user clicks
No. Access displays the NotInList error and returns to the combo. Can
someone help me suppress this error?.


CODE: *********************

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

Dim sName As String, sLast As String, sFirst As String, iComma As
Integer
Dim iReturn As Integer, varName As Variant

sName = NewData
iComma = InStr(sName, ",")

If iComma = 0 Then
sLast = sName
Else
sLast = Left(sName, iComma - 1)
sFirst = Mid(sName, iComma + 2)
End If

iReturn = MsgBox("The user " & sName & _
" is not in the system. Do you want to add this User?", _
vbQuestion + vbYesNo, CurrentProject.Properties("AppTitle").Value)
If iReturn = vbYes Then
DoCmd.OpenForm FormName:=" frmUserAdd", _
DataMode:=acAdd, WindowMode:=acDialog, OpenArgs:=sName
Response = acDataErrAdded

Else ' ERROR HAPPENS HERE

End If
Exit Sub

Response = acDataErrAdded

End Sub
 
Private Sub cbo_userID_NotInList(NewData As String, Response As Integer)

Dim sName As String, sLast As String, sFirst As String, iComma As Integer
Dim iReturn As Integer, varName As Variant

sName = NewData
iComma = InStr(sName, ",")

If iComma = 0 Then
sLast = sName
Else
sLast = Left(sName, iComma - 1)
sFirst = Mid(sName, iComma + 2)
End If

iReturn = MsgBox("The user " & sName & _
" is not in the system. Do you want to add this User?", _
vbQuestion + vbYesNo, CurrentProject.Properties("AppTitle").Value)
If iReturn = vbYes Then
DoCmd.OpenForm FormName:="frmUserAdd", _
DataMode:=acAdd, WindowMode:=acDialog, OpenArgs:=sName
Response = acDataErrAdded

Else ' ERROR HAPPENS HERE

' *** Add these 2 lines
Response = acDataErrContinue
ctl.Undo

End If
Exit Sub

' *** remove this: it's pointless
Response = acDataErrAdded

End Sub
 
Else ' ERROR HAPPENS HERE
Response = acDataErrContinue '-- Add this line of code here.
End If
 
thanks

ruralguy via AccessMonster.com said:
Else ' ERROR HAPPENS HERE
Response = acDataErrContinue '-- Add this line of code here.
End If



--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
Back
Top