Not In List Error Handling

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
 
D

Douglas J. Steele

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
 
R

ruralguy via AccessMonster.com

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top