Rabu, 22 Agustus 2012

[MS_AccessPros] Not in list

 

I am trying to adapt some code from another example for my combo box. I believe Glenn helped me with the first version.

If the user types a name into a combo box that is not on the list I want them to get a message box and if they want to add the name (select yes) I want another form to open. I entered the code below and it almost works.

The message box works, lets me know, "Name is not currently in the list" and ask the question "Do you want to add it?"

when I answer yes I get an Access error message box that says
"The text you entered isn't an item in the list"
"Select an item from the list or enter text that matches one of the listed items"

When I hit OK, the correct form is open. I just do not know how to keep this error box from showing.

This combo box looks up a record on the form so there is now two events, one on the After Update and on in the Not in List. Maybe the After Update event is triggering this message. If that is the case how do I look up a record on a form without the After Update event.

Thanks,
Bill

Private Sub cboLookup_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
Dim i As Integer
Dim Msg As String

'Exit this sub if the combo box is cleared
If NewData = "" Then Exit Sub

Msg = "'" & NewData & "' Name is not currently in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"

i = MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Client Name")
If i = vbYes Then
DoCmd.OpenForm "f_Clients", acNormal, , , acFormAdd

Else
Response = acDataErrContinue
End If
End Sub

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar