Solved prevent message "the text you Entered isnt an item in the list" (1 Viewer)

FahadTiger

Member
Local time
Today, 11:48
Joined
Jun 20, 2021
Messages
115
Hi Experts..
i used the below code for entering new record inside combobox..if i choose yes from popup message its fine
but when i choose NO..display popup message (the text you Entered isnt an item in the list)!!
How can i prevent display this message?
thank you all
----------------------
Private Sub DoctorID_NotInList(NewData As String, Response As Integer)
Dim strTmp As String
strTmp = "Add '" & NewData & "' as a new doctor?"
If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
strTmp = "INSERT INTO doctors ( DoctorName ) " & _
"SELECT """ & NewData & """ AS DoctorName;"
DBEngine(0)(0).Execute strTmp, dbFailOnError
Response = acDataErrAdded
End If
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:48
Joined
Oct 29, 2018
Messages
21,473
Try moving the Response=acDataErrAdded line outside of your If/Then block.
 

FahadTiger

Member
Local time
Today, 11:48
Joined
Jun 20, 2021
Messages
115
Try moving the Response=acDataErrAdded line outside of your If/Then block.
i did like this:
Response = acDataErrAdded
If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
but still message
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:48
Joined
Oct 29, 2018
Messages
21,473
i did like this:
Response = acDataErrAdded
If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
but still message
How about try placing it at the end?
Code:
If...
...
End If
Response = acDataErrAdded
 

FahadTiger

Member
Local time
Today, 11:48
Joined
Jun 20, 2021
Messages
115
How about try placing it at the end?
Code:
If...
...
End If
Response = acDataErrAdded
i do it before..and same thing
if there is no answer..i think the only one to change the message to force the user to click ok..and make delete button if he want to delete record in combo:
If MsgBox(strTmp, vbOKOnly + vbDefaultButton2 + vbQuestion, "Not in list") = vbOK Then
 

isladogs

MVP / VIP
Local time
Today, 09:48
Joined
Jan 14, 2017
Messages
18,223
Code:
Private Sub DoctorID_NotInList(NewData As String, Response As Integer)

Dim strTmp As String
strTmp = "Add '" & NewData & "' as a new doctor?"
If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
    strTmp = "INSERT INTO doctors ( DoctorName ) " & _
    "SELECT '" & NewData & "' AS DoctorName;"
    DBEngine(0)(0).Execute strTmp, dbFailOnError
    Response = acDataErrAdded
Else
    Response = 0
    Me.DoctorID = ""
End If

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:48
Joined
May 7, 2009
Messages
19,243
Code:
Private Sub DoctorID_NotInList(NewData As String, Response As Integer)
    Dim strTmp As String
    'add response in case "No" is the answered below question.
    Response = acDataErrContinue
    
    strTmp = "Add '" & NewData & "' as a new doctor?"
    If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
        strTmp = "INSERT INTO doctors ( DoctorName ) " & _
        "SELECT """ & NewData & """ AS DoctorName;"
        DBEngine(0)(0).Execute strTmp, dbFailOnError
        Response = acDataErrAdded
    End If
End Sub
 

Users who are viewing this thread

Top Bottom