I am hoping that someone will be able to take a look a the overall picture and see where my problem is with the NotInList business. So, I'm going to give the basic dBase structure here plus the code for NotInList.
TABLES:
Name Table
NameID (Primary Key, autonumber)
LastName (text)
Location Table
LocationID (Primary Key, autonumber)
Location (text)
Clearance Table
ClearID (Primary Key, autonumber)
DateGen (date/time)
DateExp (date/time)
NameID (foreign key, number - long integer)
LocationID (foreign key, Lookup, number - long integer)
QUERIES:
Name Query (based on Name Table)
Location Query (based on Location Table)
Clearance (based on Clearance Table)
Complete Query (based on all 3 tables) - NameID (Name Query), LastName (Name Query), ClearID (Clearance Query), DateGen (Clearance Query), DateExp (Clearance Query), LocationID (Clearance Query)
FORMS:
Note: these 1st two were generated via FormWizard basing on Complete Query
Personnel Clearance Form (NameID and LastName)
Clearance Detail Subform (ClearID, DateGen, DateExp, LocationID)
Location Form (based on Location Query with LocationID, Location)
Okay, here's the code:
Private Sub Location_NotInList(NewData As String, Response As Integer)
Dim Result
Dim Msg As String
Dim CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = " " Then Exit Sub
' Ask the user if he or she wishes to add the new customer.
Msg = " ' " & NewData & " ' is not in the list." & CR & CR
Msg = Msg & "Do you wish to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
' If the user chose Yes, start the Location Form in data entry
' mode as a dialog form, passing the new location in NewData
' to the OpenForm method's OpenArgs argument. The OpenArgs
' argument is used in Location Form's Form_Load event procedure.
DoCmd.OpenForm "Location Form", , , , acFormAdd, acDialog, NewData
End If
' Look for the location the user created in the Location Form.
Result = DLookup("[Location]", "Location Query", "[Location]=' " & NewData & " ' ")
If IsNull(Result) Then
' If the location was not created, set the Response agrument
' to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again!"
Else
' If the location was created, set the Response argument to
' indicate that the new data is being added.
Response = acDataErrAdded
End If
End Sub
Does anyone see my problem anywhere? To reiterate, if the location is not in the list, the MsgBox opens and asks if I want to add. I click yes, it opens Location Form. Location is there, along with the autonum LocationID, I click Save then Close, which is when I get the "Please try again!" MsgBox. Yet if I escape out of the Clearance Detail SubForm, close the Personnel Clearance Form, then reopen and add the same location, it's there in the combo box!
Thanks for any and all help.
[This message has been edited by tbaxter (edited 02-04-2002).]
[This message has been edited by tbaxter (edited 02-04-2002).]