Thanks for the help, I am still a little lost. I am going to spend some time reviewing the code you provided and I will reply in the morning.
Main Topics
Browse All TopicsI am trying to create a command that will allow me to close out of a form without saving the data. There are multi steps to get into the forms and at two points you should be able to exit without saving but neither are working the way I want them to.
Data is entered into a field that has an item not in list event. As you type if a matching record is not found, you press enter and the first MsgBox opens. (Pic 1)
The first MsgBox ask if you want to add the New Data, (Pic 2) but when you click no instead of returning to a empty field I get a message saying The text you entered isnt an item in the list, (Pic 3) I then have to press the esc key three times (First press closes the drop-down list, second press removes entered data from the field, third press makes field undirty.
Add New Inmate form has a Cancel button in case you entered the wrong data or just change your mind. When you click the button (Pic 6) the form closes but the data is not deleted from the record. I think the problem with this button is the data has already been saved (Pic 5) base on the fact that the Inmate involved form is no longer Dirty. I am not sure if I should have code to delete the record or if I can still use an undo command.
"This is a Bound Form
"Record Source = tblInmates
"On the Add New Inmate form the InmateID field is a Auto Number Field
I have post the code I am currently using. It does not work!!!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
theNelson,
I am hoping you can help me tackle this one problem at a time. My coding skills are not as good as I thought (haha)
The first is getting the cancel button to work for the pop-up after pressing enter when typing in NewData. I have attached a copy of the current code I am using. In the Code between the two ampersand It appears there is no instruction what to do if it = False
I think the line (DoCmd.Close acForm, "frmEditNewInmate", acSaveYes) Should be acSaveNo
You can simplify your code by replacing
If fncConfirm(strMessage) Then
and
the fncConfirm Function with
If MsgBox(strMessage, vbQuestion + vbYesNo) = vbYes Then
Is the InmateId combobox in the frmEditNewInmate form or the Report Form? If it is in the Report form, why are you opening the InmateId form since you are adding the required record with your recordset? I open a form to add the record if the user needs to enter information into the new record. Otherwise I just use an update query or recordset to add the new record (usually an update query since it is easier).
I am trying to handle this problem one issue at a time. The first is that I get a information message when I click "No" when asked if I want add the person. I have figured out how to correct that, but am still have a problem getting the comb box empty without pressing esc twice. I have explain a little better below.
I have followed the advice above and it works fine, but when I have typed in text and then click "No" when asked if I want to add the name. Changing the response to Continue suppresses the message and using SendKey Chr(vbKeyEscape) closes the dropdown, but I still have to press the esc key twice to get back to a empty form. Is there another way to clear the text entered and loose focus on the combo box?
I changed the response to acDataErrContinue from acDataErrDisplay
and added the following code. Now when I click cancel the the Info msgbox closes and the combo box is cleared.
Now I have to get the cancel to work if I click yes and the frmEdfitNewInmate form opens. I want the form to clear any data in the combo box and the table and close.
Here is the code for the "NotInList" event. I have the it working if you cancel at the first message box that ask if you want to enter the new data. You can click "No" and it closes the msgbox and clears the form. If you click yes the EditNewInmate form opens, if you click cancel the form closes, but it still enters the data in the table. I looked at he example you reference above. I tried to use the code you provide but still have the same problem of the data being entered even though I click to cancel. I think the reason is the data is being entered into a different form and I don't know how to address this.
I realize you stated this part is working but lets get rid of SendKeys. Instead of
SendKeys Chr(vbKeyEscape)
Me.InmateID = ""
SendKeys Chr(vbKeyEscape)
try
InmateID.UnDo
Me.Undo
In the code you posted, I do not see anything opening the form EditNewInmate. This code:
Set dbsCurrentDB = CurrentDb()
Set rstInmates = dbsCurrentDB.OpenRecordset
rstInmates.AddNew
rstInmates!InmateLastName = NewData
rstInmates!InmateFirstName
rstInmates!CIN = "00000"
rstInmates!InmateGender = "Male"
rstInmates.Update
writes to the table tblInmates directly.
You can close the dropdown of a combobox by setting the focus to another control then back to the combobox.
Why are you opening the form frmEditNewInmate when you have already saved the not in list new data to the table tblInmates? Since the new record is saved in the not in list event, pressing the Cancel button in the Add New Inmate form will not remove the record unless you have coding like a delete query to remove the record.
Now that I see there is design problem, but do not know how to write the query to delete the record. I started this data base, but then had someone help me complete it and this is how she constructed it. I wanted to be able to add a new person without going to a different tab, so she wrote the "NotInList Event". I like the way it works, but need to be able to cancel. When staff are making entries if they need to cancel for any reason currently they are getting stuck. Some have exited by Cntlr, Alt, Delete which then enters "000000" into the table. Then no one else can add a new inmate. The database is still usable as long as the person receiving the violation is already in the database.
To create a delete query, go to queries in the database window select, new, select the table. Under the queries menu, select delete query. Drag the star (all fields) from the table window to the first field column. Enter the criteria to select the record. Switch to SQL view and copy that. To run the query from code paste the SQL statement behind "CurrentDB.Execute". When your done it will look like this:
CurrentDB.Execute "DELETE tblInmates.* FROM tblInmates WHERE InmateID= " & Me!InmateID & ";"
Once people get used to using Ctlr, Alt, Delete or turning off the computer, it is hard to get them to stop. Your company should have a strict written policy forbidding any employee except IT personal from doing that with listed consequences. Also, doing frequent updates can protect from this sort of action. This is my back up policy for any database critical for office operation:
This is what I do to back up our database. It may seem excessive but the data is critical to our business and I am very paranoid having been a system's engineer through the 70's and 80's when hard drive crashes were common.
The backend is stored on a raid 7 disk pack. The server will email me if there is a problem.
Every half hour that the frontend is running, the frontend copies the backend to a raid 0 disk pack by shelling to the DOS copy command. The DOS copy command will copy an open file. The only time the copy is corrupted is when someone writes to the backend during the 30 seconds the copy is being made. The database deletes copies that are more than two hours old so I always have the last 4 copies. The database will email me if it runs into a problem. (These copies are very useful for things like a user saying, "I just accidental deleted everything in a memo field.")
Every night, a workstation runs MS backup zipping a copy of the BE to its harddrive. I keep all these backups for the last four months.
Every night, another workstation runs Second Copy (www.centered.com) zipping a copy to a ftp site on our hosted www.nosuffering.com site. Second Copy will email me if it runs into a problem. The data center is in California.
Every night, a third workstation runs Handy Backup which compacts and repairs and then zips the file to a ftp site on my hosted www.thenelson.name site. Handy Backup will email me if it runs into a problem. The data center is in Pennsylvania.
I also look in on all the backups a couple of times a week. This way, I am not relying on one computer or one piece of software for the backups. I have automatic offsite backups at opposite ends of the country. All of this has cost me $50 for Second Copy and Handy Backup and $9 a month for two hosted websites (which includes my websites www.nosuffering..com and www.thenelson.name).
The Sgt gets reports from various places and staff. Some times they may be in the process of entering a report that requires them to add a inmate that has never had a writeup so he/she is not in the database. So they enter the last name, press enter the form opens because it is a new person, then they realize the report is missing the CIN number or they see the report is pass the date to process it ect. Now they need to exit out of the record without adding what they have typed already.
The message box prior to this point ask "Are you sure you want to add this inmate to the database, Normally the answer is yes. But sometimes as you are adding the report the name doesn't come up which is caused by typing the name wrong so they would click no. I use the esc key, but I have thirty people that use this database and most are not very computer savvy. I keep telling them to press the esc key, but they don't remember, so I am trying to make it as simple for the user as possible.
So instead of using a message box with "Are you sure you want to add this inmate to the database?" Then having a popup form displaying the information where they can cancel the add after they said yes, Why not have the popup form replace the message box. The popup form will display the info with the question "Are you sure you want to add this inmate to the database?" and a yes and no button. This way, you are only asking once, the user has the info he needs to make the decision and you don't have to delete a record that is not needed.
Business Accounts
Answer for Membership
by: thenelsonPosted on 2009-09-15 at 07:24:23ID: 25335209
To eliminate the "the text you entered is not an item in the list popup", in the Inmate combobox NotInList event you need to set
FormTricks , "Check for required items" for an example of how to do it except the NotInList event handling.
List(NewDa ta As String, Response As Integer)
rm "YourFormNameHere", DataMode:=acFormAdd, WindowMode:=acDialog, OpenArqs:="Data,More Data,1234,#2/12/2006#"
Response = acDataErrContinue
The Inmate combobox NotInList event will fire (if the user is in it) as soon as the uses presses the Cancel button and the focus leaves the Inmate combobox and before any code in the Cancel button dick event runs so the Inmate combobox NotInList event must handle this on its own.
To not save the record and return the form to dirty = False, you need to Use the Form Before update event. Set
Cancel = True
to stop the update and stop the change to another record.
To stop the closing of the form set
Cancel = True
in the Form Unload and Form Undo events.
See www.thenelson.name/#Report
Here in a sample of NotInList event handling:
Private Sub YourComboBoxNameHere_NotIn
Dim ctl As Control
' Return Control object that points to combo box.
Set ctl = Me!YourComboBoxNameHere
' Prompt user to verify they wish to add new value.
If MsgBox("Value is not in list. Add it?", vbOKCancel) = vbOK Then
' Set Response argument to indicate that data is being added.
Response = acDataErrAdded
' Add string in NewData argument to row source when the row source is a field list.
ctl.RowSource = ctl.RowSource & ";" & NewData
'Or Open the "DataEntry" input form when the row source is a table or query
DoCmd.OpenForm "YourFormNameHere", DataMode:=acFormAdd, WindowMode:=acDialog, OpenArqs:="FillFields"
Else
' If user chooses Cancel, suppress error message
' and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
End Sub
About the OpenArqs parameter of the open form command:
OpenArqs passes a value to the opening form. In that form, you get the value using
Me.OpenArqs
For example:
Private Sub Form_Open()
If Me.OpenArgs = "FillFields" Then
'Run code to prefill all the fields from last (new) client's information
End If
End Sub
Or you can use OpenArgs to pass a bunch of comma delimited values:
DoCmd.OpenDataDoCmd.OpenFo
Private Sub Form_Open()
Dim OpenArqsArray()
If Len(Me.OpenArgs) > 0 Then
OpenArqsArray = Split(Me.OpenArgs, ",")
FieldA = OpenArqsArray(0)
FieldB = OpenArqsArray(1)
FieldC = OpenArqsArray(2)
FieldD = OpenArqsArray(3)
End If
End Sub