A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Trap error in Combo Box



 
 
Thread Tools Display Modes
  #1  
Old December 28th, 2008, 05:52 PM posted to microsoft.public.access.gettingstarted
Ray C
external usenet poster
 
Posts: 215
Default Trap error in Combo Box

Can anyone help please?
I use a Combo Box as a "Find Box" to list all available (non duplicated)
entries in a table. Great, but I also want the user to input the name that
they want to find and if the name is not in the Table, I want to trap out the
error (The Item does not exist in the List) and tell the user that the name
does not exist in the Table giving them the option "Do you want to create a
new record in that name?"
I can do this if I run the required string through the Record Set but I can
not seem to trap out the error generated by the Combo Box not being able to
find what has been entered.
Any help appreciated
Ray C
  #2  
Old December 28th, 2008, 06:04 PM posted to microsoft.public.access.gettingstarted
tina
external usenet poster
 
Posts: 1,997
Default Trap error in Combo Box

have you looked at the NotInList event property of the combobox control?

hth


"Ray C" wrote in message
...
Can anyone help please?
I use a Combo Box as a "Find Box" to list all available (non duplicated)
entries in a table. Great, but I also want the user to input the name that
they want to find and if the name is not in the Table, I want to trap out

the
error (The Item does not exist in the List) and tell the user that the

name
does not exist in the Table giving them the option "Do you want to create

a
new record in that name?"
I can do this if I run the required string through the Record Set but I

can
not seem to trap out the error generated by the Combo Box not being able

to
find what has been entered.
Any help appreciated
Ray C



  #3  
Old December 28th, 2008, 06:36 PM posted to microsoft.public.access.gettingstarted
Ken Sheridan[_2_]
external usenet poster
 
Posts: 19
Default Trap error in Combo Box

On Dec 28, 5:52*pm, Ray C wrote:
*Can anyone help please?
I use a Combo Box as a "Find Box" to list all available (non duplicated)
entries in a table. Great, but I also want the user to input the name that
they want to find and if the name is not in the Table, I want to trap out the
error (The Item does not exist in the List) and tell the user that the name
does not exist in the Table giving them the option "Do you want to create a
new record in that name?"
I can do this if I run the required string through the Record Set but I can
not seem to trap out the error generated by the Combo Box not being able to
find what has been entered.
Any help appreciated
Ray C


As Tina says, use the control's NotInList event procedure. Here's an
example which adds a City name to a Cities table:

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

Dim cmd As ADODB.Command
Dim ctrl As Control
Dim strSQL As String, strMessage As String

Set ctrl = Me.ActiveControl
strMessage = "Add " & NewData & " to list?"

strSQL = "INSERT INTO Cities(City) VALUES(""" & _
NewData & """)"

Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText

If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
cmd.CommandText = strSQL
cmd.Execute
Response = acDataErrAdded
Else
Response = acDataErrContinue
ctrl.Undo
End If

End Sub

And here's one which does the same, but in this case opens a frmCities
form so that other data than the city name, e.g. the county or state
in which the city is in can also be added to the new record:

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

Dim ctrl As Control
Dim strMessage As String

Set ctrl = Me.ActiveControl
strMessage = "Add " & NewData & " to list?"

If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
DoCmd.OpenForm "frmCities", _
DataMode:=acFormAdd, _
WindowMode:=acDialog, _
OpenArgs:=NewData
' ensure frmCities closed
DoCmd.Close acForm, "frmCities"
' ensure city has been added
If Not IsNull(DLookup("CityID", "Cities", "City = """ & _
NewData & """")) Then
Response = acDataErrAdded
Else
strMessage = NewData & " was not added to Cities table."
MsgBox strMessage, vbInformation, "Warning"
Response = acDataErrContinue
ctrl.Undo
End If
Else
Response = acDataErrContinue
ctrl.Undo
End If

End Sub

With this second example the following code also goes in the frmCities
form's Open event procedure to set the DefaultValue property of the
City control on the form to the name of the city added in the combo
box:

Private Sub Form_Open(Cancel As Integer)

If Not IsNull(Me.OpenArgs) Then
Me.City.DefaultValue = """" & Me.OpenArgs & """"
End If

End Sub

Ken Sheridan
Stafford, England

  #4  
Old December 29th, 2008, 04:18 AM posted to microsoft.public.access.gettingstarted
bigbolokbob
external usenet poster
 
Posts: 3
Default Trap error in Combo Box

looking for models for soft core porn
great rates get in touch females only
  #5  
Old December 29th, 2008, 10:18 PM posted to microsoft.public.access.gettingstarted
Ray C
external usenet poster
 
Posts: 215
Default Trap error in Combo Box

This is great Ken, I don't know why i did not work that out for myself. Thank
you so much for your help.

Regards Ray C


"Ken Sheridan" wrote:

On Dec 28, 5:52 pm, Ray C wrote:
Can anyone help please?
I use a Combo Box as a "Find Box" to list all available (non duplicated)
entries in a table. Great, but I also want the user to input the name that
they want to find and if the name is not in the Table, I want to trap out the
error (The Item does not exist in the List) and tell the user that the name
does not exist in the Table giving them the option "Do you want to create a
new record in that name?"
I can do this if I run the required string through the Record Set but I can
not seem to trap out the error generated by the Combo Box not being able to
find what has been entered.
Any help appreciated
Ray C


As Tina says, use the control's NotInList event procedure. Here's an
example which adds a City name to a Cities table:

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

Dim cmd As ADODB.Command
Dim ctrl As Control
Dim strSQL As String, strMessage As String

Set ctrl = Me.ActiveControl
strMessage = "Add " & NewData & " to list?"

strSQL = "INSERT INTO Cities(City) VALUES(""" & _
NewData & """)"

Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText

If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
cmd.CommandText = strSQL
cmd.Execute
Response = acDataErrAdded
Else
Response = acDataErrContinue
ctrl.Undo
End If

End Sub

And here's one which does the same, but in this case opens a frmCities
form so that other data than the city name, e.g. the county or state
in which the city is in can also be added to the new record:

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

Dim ctrl As Control
Dim strMessage As String

Set ctrl = Me.ActiveControl
strMessage = "Add " & NewData & " to list?"

If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then
DoCmd.OpenForm "frmCities", _
DataMode:=acFormAdd, _
WindowMode:=acDialog, _
OpenArgs:=NewData
' ensure frmCities closed
DoCmd.Close acForm, "frmCities"
' ensure city has been added
If Not IsNull(DLookup("CityID", "Cities", "City = """ & _
NewData & """")) Then
Response = acDataErrAdded
Else
strMessage = NewData & " was not added to Cities table."
MsgBox strMessage, vbInformation, "Warning"
Response = acDataErrContinue
ctrl.Undo
End If
Else
Response = acDataErrContinue
ctrl.Undo
End If

End Sub

With this second example the following code also goes in the frmCities
form's Open event procedure to set the DefaultValue property of the
City control on the form to the name of the city added in the combo
box:

Private Sub Form_Open(Cancel As Integer)

If Not IsNull(Me.OpenArgs) Then
Me.City.DefaultValue = """" & Me.OpenArgs & """"
End If

End Sub

Ken Sheridan
Stafford, England


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:55 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.