Group:  Microsoft Access ยป microsoft.public.access.forms
Thread: Combo "Not in List Event", MS generic message still appears

Geek News

Combo "Not in List Event", MS generic message still appears
"basiltabethacat" <u48523[ at ]uwe> 12/31/2008 9:45:36 AM
Hi,

I'm writing a database to help teachers write Unit Plans, containing several
tabs of hierarchical information, both within the tabs and between the tabs.
I'm trying to use a combo box to display current choices, but allow the user
to start a brand new Unit Plan (a relational table upon which many other
choices and related information and tables will hinge and be added to.

My form fields/Associated table fields

cboPlanName/PlanName
txtYearOfTeaching/TermYear
txtTermNumber/Term/Number

The code I have placed into the "Not in List" event is:

Private Sub cboPlanName_NotInList(NewData As String, Response As Integer)
Dim msgstr As String

msgstr = "You have entered a new Unit Plan name. Do you really want to
begin a new Unit Plan?"

If MsgBox(msgstr, vbYesNo, "Create new Unit Plan?") = vbYes Then
Response = acDataErrAdded
CurrentDb.Execute ("INSERT INTO [Term Plans](PlanName) SELECT '" &
NewData & "' AS Expr1;")

Else
repsonse = acDataErrContinue
Me.cboPlanName.Undo
End If
End Sub

Although I have placed the acDataErrAdded and acDataErrContinue commands, the
MS generic error messages still persist. I want my cbo box to save the new
entry, and then if vbYes, enable and null the text boxes, ready for the user
to enter the associated information to complete the record, if vbNo return
the user to the cbo box to make another choice with no info saved.

I'm an absolute beginner. I sort of understand what all the code does except
for the actual execution code, which is, of course, copied and adapted (any
suggested tutorials regarding this aspect would be appreciated).

Why do I still get the MS generic error messages?

RE: Combo "Not in List Event", MS generic message still appears
MikeJohnB 12/31/2008 2:18:01 PM
I am not sure what you are trying to do from your code acdataerradded?

Take alook at

DoCmd.SetWarnings False

But always follow this with

DoCmd.SetWarnings True

Before you exit the procedure, normally after the line which throws up the
generic Access Response.

Regards

Mike B
--
Advice to Posters.
Check your post for replies or request for more information.
Consider providing some feed back to the response you have recieved.
Kindest Regards Mike B


"basiltabethacat" wrote:

[Quoted Text]
> Hi,
>
> I'm writing a database to help teachers write Unit Plans, containing several
> tabs of hierarchical information, both within the tabs and between the tabs.
> I'm trying to use a combo box to display current choices, but allow the user
> to start a brand new Unit Plan (a relational table upon which many other
> choices and related information and tables will hinge and be added to.
>
> My form fields/Associated table fields
>
> cboPlanName/PlanName
> txtYearOfTeaching/TermYear
> txtTermNumber/Term/Number
>
> The code I have placed into the "Not in List" event is:
>
> Private Sub cboPlanName_NotInList(NewData As String, Response As Integer)
> Dim msgstr As String
>
> msgstr = "You have entered a new Unit Plan name. Do you really want to
> begin a new Unit Plan?"
>
> If MsgBox(msgstr, vbYesNo, "Create new Unit Plan?") = vbYes Then
> Response = acDataErrAdded
> CurrentDb.Execute ("INSERT INTO [Term Plans](PlanName) SELECT '" &
> NewData & "' AS Expr1;")
>
> Else
> repsonse = acDataErrContinue
> Me.cboPlanName.Undo
> End If
> End Sub
>
> Although I have placed the acDataErrAdded and acDataErrContinue commands, the
> MS generic error messages still persist. I want my cbo box to save the new
> entry, and then if vbYes, enable and null the text boxes, ready for the user
> to enter the associated information to complete the record, if vbNo return
> the user to the cbo box to make another choice with no info saved.
>
> I'm an absolute beginner. I sort of understand what all the code does except
> for the actual execution code, which is, of course, copied and adapted (any
> suggested tutorials regarding this aspect would be appreciated).
>
> Why do I still get the MS generic error messages?
>
>
Re: Combo "Not in List Event", MS generic message still appears
"BruceM" <bamoob[ at ]yawhodotcalm.not> 12/31/2008 3:36:18 PM
You could try putting the Response = ... line at the end of the section of
code (after inserting the new record, or after the undo). I'm not familiar
with using the NotInList exactly in the way you have done, but I have had
good success with code based on the following:
http://www.mvps.org/access/forms/frm0015.htm

Another approach is here:
http://www.datastrat.com/Code/NotInListCode.txt

I don't think SetWarnings will do anything to suppress the error messages.

"basiltabethacat" <u48523[ at ]uwe> wrote in message news:8f7a6bdfd8049[ at ]uwe...
[Quoted Text]
> Hi,
>
> I'm writing a database to help teachers write Unit Plans, containing
> several
> tabs of hierarchical information, both within the tabs and between the
> tabs.
> I'm trying to use a combo box to display current choices, but allow the
> user
> to start a brand new Unit Plan (a relational table upon which many other
> choices and related information and tables will hinge and be added to.
>
> My form fields/Associated table fields
>
> cboPlanName/PlanName
> txtYearOfTeaching/TermYear
> txtTermNumber/Term/Number
>
> The code I have placed into the "Not in List" event is:
>
> Private Sub cboPlanName_NotInList(NewData As String, Response As Integer)
> Dim msgstr As String
>
> msgstr = "You have entered a new Unit Plan name. Do you really want to
> begin a new Unit Plan?"
>
> If MsgBox(msgstr, vbYesNo, "Create new Unit Plan?") = vbYes Then
> Response = acDataErrAdded
> CurrentDb.Execute ("INSERT INTO [Term Plans](PlanName) SELECT '" &
> NewData & "' AS Expr1;")
>
> Else
> repsonse = acDataErrContinue
> Me.cboPlanName.Undo
> End If
> End Sub
>
> Although I have placed the acDataErrAdded and acDataErrContinue commands,
> the
> MS generic error messages still persist. I want my cbo box to save the new
> entry, and then if vbYes, enable and null the text boxes, ready for the
> user
> to enter the associated information to complete the record, if vbNo return
> the user to the cbo box to make another choice with no info saved.
>
> I'm an absolute beginner. I sort of understand what all the code does
> except
> for the actual execution code, which is, of course, copied and adapted
> (any
> suggested tutorials regarding this aspect would be appreciated).
>
> Why do I still get the MS generic error messages?
>

Re: Combo "Not in List Event", MS generic message still appears
"basiltabethacat via AccessMonster.com" <u48523[ at ]uwe> 1/1/2009 4:37:59 AM
Thank you both for your time.

I tried "The Access Web" option (the first link) code:

Private Sub cboPlanName_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String

strMsg = "'" & NewData & "' is not an available Unit Plan. " & vbCrLf &
vbCrLf
strMsg = strMsg & "Do you want to create a new Unit Plan?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to create a New Unit Plan
or No to choose and existing one."

If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new Unit Plan?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("Term Plans", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs![Term Plans] = NewData
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If

End If

rs.Close
Set rs = Nothing
Set db = Nothing
End Sub

...only altering message dialogue and the database to "Plan Terms" (my db).

**Choosing Yes throws me straight to "An error occurred. Please try again."
without adding my new option to the list. Why does it ignore the first part
of the Else statement?

**Choosing No throws up run-time error 91, "Object variable or With block
variable not set" , the yellow debug highlight bar sits on "rs.Close" when
the code is opened via the bug message. Evidently this message has something
to do with incorrect setting of the variables?? Or Object libraries - I have
DAO 3.6 and ADO 2.1 selected - is this right?

Thanks.

PS Once again, I'm a complete beginner and don't really know what I'm talking
about ;-) - just trying to find solutions via the net.

BruceM wrote:
[Quoted Text]
>You could try putting the Response = ... line at the end of the section of
>code (after inserting the new record, or after the undo). I'm not familiar
>with using the NotInList exactly in the way you have done, but I have had
>good success with code based on the following:
>http://www.mvps.org/access/forms/frm0015.htm
>
>Another approach is here:
>http://www.datastrat.com/Code/NotInListCode.txt
>
>I don't think SetWarnings will do anything to suppress the error messages.
>
>> Hi,
>>
>[quoted text clipped - 47 lines]
>>
>> Why do I still get the MS generic error messages?

--
Message posted via http://www.accessmonster.com

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net