Open form On not in list

B

Byron

Here is the code that I am using on a form to open another
form using the OnNotInList event of the combo box,
including a message to the user. I am opening this form in
the "Add" mode (see the parameter in the DoCmd.OpenForm
method). Watch out for word wraping!

Private Sub cboAdjusterTitleID_NotInList(NewData As
String, Response As Integer)
'you won't need the statement above, as it will already
'be there

'just place the code below in the On Not In List event
Dim strMsg As String, strFName As String, strLname As
String, strListType As String
Dim vbResponse

'stop the error messages
Response = acDataErrContinue
'used in message to user
strListType = "Manager's Titles"
strMsg = "Value Not In List!" & vbNewLine & vbNewLine
& "The value you entered, """ & NewData & """, is not " _
& "in the list." & vbNewLine & vbNewLine & "Do you
want to add the value """ & NewData & """" & vbNewLine
& "to the list of """ & strListType & """?"
vbResponse = MsgBox(strMsg, vbInformation +
vbDefaultButton1 + vbYesNo, "Add New List Value?")
If vbResponse = vbYes Then
DoCmd.OpenForm "frmManagersTitles", acNormal, , ,
acFormAdd
'here I turn off the navigation button so the user
'cannot move off the new record
Forms![frmManagersTitles].NavigationButtons = False
'place the new value in the text box on the form
With Forms!frmManagersTitles.txtManagerTitle
'the "NewData" variable comes from the OnNotInList
' event and is provided when the event fires
.Value = NewData
.SetFocus
End With
End If
End Sub

HTH
Byron
-----Original Message-----
Hi,
I'm trying to open a form when data is not in list. This
form would allow me to format the missing field precisely
before adding it. However, whatever I do, Access always
gives me the "OpenForm event cancelled" when I try to open
my input form, because Access is trying to make me choose
from the drop down list just as I'm trying to open the
form.
Is there a way to stop Access from trying to add the new
item in the drop down list before I display my form and
input the new data?
 

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