Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Combo Box - Not In List Event

Status
Not open for further replies.

kramsey

Technical User
Jan 16, 2003
5
US
I have a form with several combo boxes and would like to be able to add a record to the underlying table when the selection I want is not in the list. Does anyone have an idea on how to write the code behind the NotInList Event?
 
The following is from Microsoft's 'Solutions' sample database in Acc97 - it should get you started:

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

' Add a new category by typing a name in CategoryID combo box.

Dim intNewCategory As Integer, intTruncateName As Integer, strTitle As String, intMsgDialog As Integer

' Display message box asking if user wants to add a new category.
strTitle = "Category Not In List"
intMsgDialog = vbYesNo + vbQuestion + vbDefaultButton1
intNewCategory = MsgBox("Do you want to add a new category?", intMsgDialog, strTitle)

If intNewCategory = vbYes Then
' Remove new name from CategoryID combo box so
' control can be requeried when user returns to form.
DoCmd.RunCommand acCmdUndo

' Display message box and adjust length of value entered in
' CategoryID combo box.
strTitle = "Name Too Long"
intMsgDialog = vbOKOnly + vbExclamation
If Len(NewData) > 15 Then
intTruncateName = MsgBox("Category names can be no longer than " _
& "15 characters. The name you entered will be truncated.", _
intMsgDialog, strTitle)
NewData = Left(NewData, 15)
End If

' Open AddCategory form.
DoCmd.OpenForm "AddCategory", acNormal, , , acAdd, acDialog, NewData

' Continue without displaying default error message.
Response = acDataErrAdded
End If


End Sub
 
Hi!

Look at this FAQ:


faq181-66

hth

Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top