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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Item not in Combo Box Problem

Status
Not open for further replies.

bill1one

Programmer
Sep 29, 2004
93
US
I have a combobox called cmbTitle. If a user enters a title not in the box, I want them to have the option of opening a form to add the title or canceling the action.

Here is the code I have running:

Private Sub cmbTitle_NotInList(NewData As String, response As Integer)

Dim msg As String
Dim Title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "The title you are entering is not in the list." & vbCrLf & _
"Do you wish to enter it now?"
style = MsgBoxStyle.YesNo
Title = "Add Title"

response = MsgBox(msg, style, Title)

If response = MsgBoxResult.Yes Then
DoCmd.OpenForm "frmNewTitle", acNormal
End If

End Sub

For some reason I keep getting a "user-defined type not defined" error. I have had this problem in the past with other databases and fixed it by adding references. Any suggestions?
 
Private Sub cmbTitle_NotInList(NewData As String, Response As Integer)
Dim msg As String
Dim Title As String
Dim style As Integer
Dim resp As Integer
msg = "The title you are entering is not in the list." & vbCrLf & _
"Do you wish to enter it now?"
style = vbYesNo
Title = "Add Title"
resp = MsgBox(msg, style, Title)
If resp = vbYes Then
DoCmd.OpenForm "frmNewTitle", acNormal, , , ,acDialog
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi bill1one,

What are...

style = MsgBoxStyle.YesNo

and

If response = MsgBoxResult.Yes Then

I presume msgboxstyle and msgboxresult are functions you created. If not then try..
Code:
Private Sub cmbTitle_NotInList()

Dim msg As String
Dim Title As String
msg = "The title you are entering is not in the list." & vbCrLf & "Do you wish to enter it now?"
Title = "Add Title"

If MsgBox(msg, acYesNo, Title) = acYes Then
   DoCmd.OpenForm "frmNewTitle", acNormal
End If

End Sub

Program Error
Programmers do it one finger at a time!
 
How are bill1one . . . . .

Besides the error you received, [blue]you have to consider what to do if a user aborts entering a title in frmNewTitle![/blue]

So, in the [blue]declaration section[/blue] of a module in the modules window, copy/paste the following public variable:
Code:
[blue]Public flgNIL As Boolean[/blue]
In frmNewTitle [purple]its up to you to set the flgNil if a title was acutally saved![/purple]

Then in the [blue]NotInList[/blue] event of the combo, copy/paste the following:
Code:
[blue]   Dim Msg As String, Style As Integer, Title As String
   Dim NL As String, DL As String
   
   NL = vbNewLine
   DL = NL & NL
   
   Msg = "The title you are entering is not in the list!" & NL & _
         "Do you wish to enter it now?" & DL & _
         "Click 'Yes' to enter." & DL & _
         "Click 'No' to abort . . ."
   Style = vbQuestion + vbOKOnly
   Title = "Data Not in List detected! . . ."
   
   If MsgBox(Msg, Style, Title) = vbYes Then
       DoCmd.OpenForm "frmNewTitle",acNormal, , , , [purple][b]acDialog[/b][/purple]
       
       If flgNil Then
         Response = acDataErrAdded
      Else
         Response = acDataErrContinue
      End If
   Else
      Response = acDataErrContinue
   End If[/blue]
Note: [purple]acDialog[/purple] cause the code in the NotInList event to stop running until you close frmNewTitle!

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top