NotInList Event Procedure Not Working

S

skyrise

I have a small amount of experience with Access. A researcher has asked me
to build a database to hold data pulled from published studies: Publication
Name, Location of Study, Particpant Data, etc. The researcher wants several
List fields in the the database to be updatable by the users. For example,
instead of loading many possible Publications Names up front into a large
Combo Box, allow an exact list of publications to be created as the users
come across them. I can't get the Event Procedure to work and don't know
what I need to do to fix it. This is the main thing that is holding up the
build of the database. The database is needed within the next few days.
PLEASE HELP!

Publication Name can be used as the example (I'm assuming the other fields
can be set up the same way).

I've created a Lookup Table called "lkpPublicationName" to hold the list of
publication names.
The table fields:
PublicationNameID - Primary Key autonumber.
PublicationName - Text field set to Allow Zero Length = Yes, Indexed = Yes
(No Duplicates)

I'm using a form called "PublicationData" to created records. Fields such as
"Publication Name" are being added in the Form Design view as Bound Combo
Boxes that use a SELECT Query to pull the user selected information from it's
Lookup Table and place it in the field on the form.

The PublicationData Table has primarily two fields of it's own:
PublicationRecordID - Primary Key autonumber.
PublicationNumber - Text field to enter the code that ID's the publication.

All other fields are represented in the table by the Primary Key field from
their corresponding LookupTable (to link to the combo box that will be added
on the form). These fields are set as Numbers with Properties of Field Size
= Long Integer, Indexed = Yes (Duplicates ok). Some of these fields are:

PublicationNameID
PubYearID
StudyLocationID
Etc.

Here is the SELECT Query for Publication Name:

SELECT [lkpPublicationName].[PublicationNameID], [lkpPublicationName].
[PublicationName] FROM lkpJournalName;


The names for the Combo Boxes appears as the name that Access automatically
assigns.
The name for the Publication Name Combo Box is Combo13.

Here is the NotInList Event Procedure for Publication Name:

Private Sub Combo13_NotInList(NewData As String, Response As Integer)
On Error GoTo Combo13_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The publication name " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Add Publication Name?")
If intAnswer = vbYes Then
strSQL = "INSERT INTO lkpPublicationName ([PublicationName]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new publication name has been added to the list." _
, vbInformation, "Publication Name Added"
Response = acDataErrAdded
Else
MsgBox "Please choose a publication name from the list." _
, vbInformation, "Use Publication Name List"
Response = acDataErrContinue
End If
Combo13_NotInList_Exit:
Exit Sub
Combo13_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume Combo13_NotInList_Exit
End Sub
 
K

Ken Snell \(MVP\)

Did you set the Limit to List property for the combobox to Yes?

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


skyrise said:
I have a small amount of experience with Access. A researcher has asked me
to build a database to hold data pulled from published studies:
Publication
Name, Location of Study, Particpant Data, etc. The researcher wants
several
List fields in the the database to be updatable by the users. For
example,
instead of loading many possible Publications Names up front into a large
Combo Box, allow an exact list of publications to be created as the users
come across them. I can't get the Event Procedure to work and don't know
what I need to do to fix it. This is the main thing that is holding up
the
build of the database. The database is needed within the next few days.
PLEASE HELP!

Publication Name can be used as the example (I'm assuming the other fields
can be set up the same way).

I've created a Lookup Table called "lkpPublicationName" to hold the list
of
publication names.
The table fields:
PublicationNameID - Primary Key autonumber.
PublicationName - Text field set to Allow Zero Length = Yes, Indexed = Yes
(No Duplicates)

I'm using a form called "PublicationData" to created records. Fields such
as
"Publication Name" are being added in the Form Design view as Bound Combo
Boxes that use a SELECT Query to pull the user selected information from
it's
Lookup Table and place it in the field on the form.

The PublicationData Table has primarily two fields of it's own:
PublicationRecordID - Primary Key autonumber.
PublicationNumber - Text field to enter the code that ID's the
publication.

All other fields are represented in the table by the Primary Key field
from
their corresponding LookupTable (to link to the combo box that will be
added
on the form). These fields are set as Numbers with Properties of Field
Size
= Long Integer, Indexed = Yes (Duplicates ok). Some of these fields are:

PublicationNameID
PubYearID
StudyLocationID
Etc.

Here is the SELECT Query for Publication Name:

SELECT [lkpPublicationName].[PublicationNameID], [lkpPublicationName].
[PublicationName] FROM lkpJournalName;


The names for the Combo Boxes appears as the name that Access
automatically
assigns.
The name for the Publication Name Combo Box is Combo13.

Here is the NotInList Event Procedure for Publication Name:

Private Sub Combo13_NotInList(NewData As String, Response As Integer)
On Error GoTo Combo13_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The publication name " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Add Publication Name?")
If intAnswer = vbYes Then
strSQL = "INSERT INTO lkpPublicationName ([PublicationName]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new publication name has been added to the list." _
, vbInformation, "Publication Name Added"
Response = acDataErrAdded
Else
MsgBox "Please choose a publication name from the list." _
, vbInformation, "Use Publication Name List"
Response = acDataErrContinue
End If
Combo13_NotInList_Exit:
Exit Sub
Combo13_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume Combo13_NotInList_Exit
End Sub
 
S

skyrise

These are the primary Properties settings:
Row Source = the SELECT Query Statement
Row Source Type = Table/Query
Bound Column = 1
Limit To List = Yes
Allow Value List Edits = Yes
List Items Edit Form - (Blank - nothing selected)
Enabled = Yes
Locked = Yes
Did you set the Limit to List property for the combobox to Yes?
I have a small amount of experience with Access. A researcher has asked me
to build a database to hold data pulled from published studies:
[quoted text clipped - 87 lines]
Resume Combo13_NotInList_Exit
End Sub
 
S

skyrise

An additional item to note is that some of the Tables for some of the Combo
Boxes contain an additional field for a Score Value of the selection.

For Example:
Ethnicity
White = 1
African American = 2
Hispanic = 3
Etc.

Are there any modifications that need to be made to the SQL script for a user
who is adding a new ethinic group? Does something have to be added to ask to
input the Score Value as well?
These are the primary Properties settings:
Row Source = the SELECT Query Statement
Row Source Type = Table/Query
Bound Column = 1
Limit To List = Yes
Allow Value List Edits = Yes
List Items Edit Form - (Blank - nothing selected)
Enabled = Yes
Locked = Yes
On Not In List = Event Procedure
Did you set the Limit to List property for the combobox to Yes?
[quoted text clipped - 3 lines]
 
K

Ken Snell \(MVP\)

If the combo box is locked, then the user is unable to do anything in the
combo box with respect to entering data or selecting an item. Therefore, the
NotInList event procedure cannot be run because the event never occurs.

Have you put breakpoints in the event procedure to be sure that it's not
running -- perhaps it's erroring right away and exiting the procedure
through the error handler?

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/



skyrise said:
These are the primary Properties settings:
Row Source = the SELECT Query Statement
Row Source Type = Table/Query
Bound Column = 1
Limit To List = Yes
Allow Value List Edits = Yes
List Items Edit Form - (Blank - nothing selected)
Enabled = Yes
Locked = Yes
Did you set the Limit to List property for the combobox to Yes?
I have a small amount of experience with Access. A researcher has asked
me
to build a database to hold data pulled from published studies:
[quoted text clipped - 87 lines]
Resume Combo13_NotInList_Exit
End Sub
 
S

skyrise

Sorry, my mistake. The Locked Property is set to "No". I wish that was the
problem.
If the combo box is locked, then the user is unable to do anything in the
combo box with respect to entering data or selecting an item. Therefore, the
NotInList event procedure cannot be run because the event never occurs.

Have you put breakpoints in the event procedure to be sure that it's not
running -- perhaps it's erroring right away and exiting the procedure
through the error handler?
These are the primary Properties settings:
Row Source = the SELECT Query Statement
[quoted text clipped - 15 lines]
 
K

Ken Snell \(MVP\)

What are the ColumnWidths and ColumnCount properties?

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


skyrise said:
Sorry, my mistake. The Locked Property is set to "No". I wish that was
the
problem.
If the combo box is locked, then the user is unable to do anything in the
combo box with respect to entering data or selecting an item. Therefore,
the
NotInList event procedure cannot be run because the event never occurs.

Have you put breakpoints in the event procedure to be sure that it's not
running -- perhaps it's erroring right away and exiting the procedure
through the error handler?
These are the primary Properties settings:
Row Source = the SELECT Query Statement
[quoted text clipped - 15 lines]
Resume Combo13_NotInList_Exit
End Sub
 
K

Ken Snell \(MVP\)

Also, is your SQL statement correct for the combo box:

SELECT [lkpPublicationName].[PublicationNameID], [lkpPublicationName].
[PublicationName] FROM lkpJournalName;

You're selecting data from a table called lkpJournalName, but the fields are
from the table lkpPublicationName ?

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


skyrise said:
Sorry, my mistake. The Locked Property is set to "No". I wish that was
the
problem.
If the combo box is locked, then the user is unable to do anything in the
combo box with respect to entering data or selecting an item. Therefore,
the
NotInList event procedure cannot be run because the event never occurs.

Have you put breakpoints in the event procedure to be sure that it's not
running -- perhaps it's erroring right away and exiting the procedure
through the error handler?
These are the primary Properties settings:
Row Source = the SELECT Query Statement
[quoted text clipped - 15 lines]
Resume Combo13_NotInList_Exit
End Sub
 
S

skyrise

The table was renamed to lkpPublicationName. Missed changing that one after
the FROM statement. No effect on the Event Procedure though.

When I go back to the form and try to input a new publication name, I get the
Access default error message, "The text you entered is not in the list.
Select and item in the list, or enter text that matches one of the listed
items." So it seems like it is erroring rigt away and exiting the procedure
through that Error Handler.

I put in a break point on the first line and tried to add new text.
Immediately got the error message.
Also, is your SQL statement correct for the combo box:

SELECT [lkpPublicationName].[PublicationNameID], [lkpPublicationName].
[PublicationName] FROM lkpJournalName;

You're selecting data from a table called lkpJournalName, but the fields are
from the table lkpPublicationName ?
Sorry, my mistake. The Locked Property is set to "No". I wish that was
the
[quoted text clipped - 14 lines]
 
K

Ken Snell \(MVP\)

See my other post for question about the combobox's SQL statement for
RowSource property.

How do you know that the event procedure is not running? Did you try
breakpoints, as I suggested previously?

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


skyrise said:
Column Count = 2
Column Width = 0";2.073"
What are the ColumnWidths and ColumnCount properties?
Sorry, my mistake. The Locked Property is set to "No". I wish that was
the
[quoted text clipped - 14 lines]
Resume Combo13_NotInList_Exit
End Sub
 
S

skyrise

The references to the table name match. I put in a break line on the first
line of the script. Tried to enter new text, and got the error message.
See my other post for question about the combobox's SQL statement for
RowSource property.

How do you know that the event procedure is not running? Did you try
breakpoints, as I suggested previously?
Column Count = 2
Column Width = 0";2.073"
[quoted text clipped - 6 lines]
 
K

Ken Snell \(MVP\)

This sounds to me as if the form is not connecting with the event procedure
for the combobox NotInList event. If the code is not stopping on the first
line of code in your event procedure, and instead you see the built-in error
message, then that definitely indicates that the event procedure is not
running.

Let's try a few things. Copy all your code for the NotInList procedure, and
put it in a notepad file. Then delete the code from the form's module. Save
and close the form. Reopen the form and open Visual Basic Editor. Paste the
code back into the module. This will allow the form to reconnect the
procedure to the correct event (assuming that the name of the procedure
matches the actual name of your combo box control).

Then, if that does not result in the code running the way you expect, put a
breakpoint on the following lines in your event procedure (see the lines
with ' **** at the end of the code step):

Private Sub Combo13_NotInList(NewData As String, Response As Integer)
On Error GoTo Combo13_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The publication name " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Add Publication Name?") ' ****
If intAnswer = vbYes Then
strSQL = "INSERT INTO lkpPublicationName ([PublicationName]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new publication name has been added to the list." _
, vbInformation, "Publication Name Added"
Response = acDataErrAdded
Else
MsgBox "Please choose a publication name from the list." _
, vbInformation, "Use Publication Name List"
Response = acDataErrContinue
End If
Combo13_NotInList_Exit:
Exit Sub ' ****
Combo13_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error" ' ****
Resume Combo13_NotInList_Exit
End Sub


Try entering a value not in the combo box's list, and see which breakpoint
is activated.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/



skyrise said:
The table was renamed to lkpPublicationName. Missed changing that one
after
the FROM statement. No effect on the Event Procedure though.

When I go back to the form and try to input a new publication name, I get
the
Access default error message, "The text you entered is not in the list.
Select and item in the list, or enter text that matches one of the listed
items." So it seems like it is erroring rigt away and exiting the
procedure
through that Error Handler.

I put in a break point on the first line and tried to add new text.
Immediately got the error message.
Also, is your SQL statement correct for the combo box:

SELECT [lkpPublicationName].[PublicationNameID], [lkpPublicationName].
[PublicationName] FROM lkpJournalName;

You're selecting data from a table called lkpJournalName, but the fields
are
from the table lkpPublicationName ?
Sorry, my mistake. The Locked Property is set to "No". I wish that was
the
[quoted text clipped - 14 lines]
Resume Combo13_NotInList_Exit
End Sub
 
S

skyrise via AccessMonster.com

I did the copy and repaste with no change in outcome. I'm not familiar
enough with Breakpoints to know what to look for or expect from them when
using. I added the 3 breakpoints that you suggested and tried to enter new
text. No change in outcome. The default error message pops up to indicate
that the text is not in the established list.

I guess this forum doesn't allow attached files? I would attach a sample
copy database of what I'm trying to create.
This sounds to me as if the form is not connecting with the event procedure
for the combobox NotInList event. If the code is not stopping on the first
line of code in your event procedure, and instead you see the built-in error
message, then that definitely indicates that the event procedure is not
running.

Let's try a few things. Copy all your code for the NotInList procedure, and
put it in a notepad file. Then delete the code from the form's module. Save
and close the form. Reopen the form and open Visual Basic Editor. Paste the
code back into the module. This will allow the form to reconnect the
procedure to the correct event (assuming that the name of the procedure
matches the actual name of your combo box control).

Then, if that does not result in the code running the way you expect, put a
breakpoint on the following lines in your event procedure (see the lines
with ' **** at the end of the code step):

Private Sub Combo13_NotInList(NewData As String, Response As Integer)
On Error GoTo Combo13_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The publication name " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Add Publication Name?") ' ****
If intAnswer = vbYes Then
strSQL = "INSERT INTO lkpPublicationName ([PublicationName]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new publication name has been added to the list." _
, vbInformation, "Publication Name Added"
Response = acDataErrAdded
Else
MsgBox "Please choose a publication name from the list." _
, vbInformation, "Use Publication Name List"
Response = acDataErrContinue
End If
Combo13_NotInList_Exit:
Exit Sub ' ****
Combo13_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error" ' ****
Resume Combo13_NotInList_Exit
End Sub

Try entering a value not in the combo box's list, and see which breakpoint
is activated.
The table was renamed to lkpPublicationName. Missed changing that one
after
[quoted text clipped - 25 lines]
 
S

skyrise via AccessMonster.com

I think that I resolved the issue. (TY:scottmcd9999)

I selected the "Compact and Repair" function and enabled Macros on the
database. Both of those things has the NotInList Event Procedure working.
I did the copy and repaste with no change in outcome. I'm not familiar
enough with Breakpoints to know what to look for or expect from them when
using. I added the 3 breakpoints that you suggested and tried to enter new
text. No change in outcome. The default error message pops up to indicate
that the text is not in the established list.

I guess this forum doesn't allow attached files? I would attach a sample
copy database of what I'm trying to create.
This sounds to me as if the form is not connecting with the event procedure
for the combobox NotInList event. If the code is not stopping on the first
[quoted text clipped - 49 lines]
 

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