Solved

Closing Data Entry Form without saving

Posted on 2008-06-23
7
765 Views
Last Modified: 2013-11-28
I am creating a database using MS Access 2003.  I created a data entry form with several command buttons.  I am having an issue with the "Cancel and Close" button.  What I want is even if someone has entered data into the various list-boxes, text boxes, etc, I want this button to close the form, and not store any entered data in the table.  I have tried:

DoCmd.Close acForm, "<Form Name>", acSaveNo

But this still stores the data in the table...
0
Comment
Question by:Michael2008
  • 4
  • 2
7 Comments
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 21848137
- Have cmdCancel and cmdSave on your form.
- Remove the control source of all the controls you have.
- When you hit cmdCancel, for is to close without saving a thing.
- When you hit cmdSave, using code like below saves your info:

CurrentDB.Execute "Insert Into Table1(CustName, Amount) Values(" & chr(34) & me!txtCustName & chr(34) & ", " & Me!txtSales & ")"

Mike
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 21848144
CurrentDB.Execute "Insert Into Table1(CustName, Amount, SoldDate) Values(" & chr(34) & me!txtCustName & chr(34) & ", " & Me!txtSales & ", #" & me!txtDate & "#)"
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 21848157
Values(" & chr(34) & me!txtCustName & chr(34) & ",    
is to handle cases like O'Brian     <----- has ' in it

If you would never have cases like O'Brian, then use:


Rank: Master
Is this what you were looking for?Yes No
eghtebas:
CurrentDB.Execute "Insert Into Table1(CustName, Amount, SoldDate) Values('" & me!txtCustName & "', " & Me!txtSales & ", #" & me!txtDate & "#)"
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 21848160
sorry... Ignore:

Rank: Master
Is this what you were looking for?Yes No
eghtebas:


part
0
 

Author Comment

by:Michael2008
ID: 21848773
Ok, so say I have four main fields: Section, Title, Applicability, and Description
Section is a number, Description is a memo, and the other two are just text
In the VBA for the "Save", this is the line I have, and it doesn't like it:

CurrentDb.Execute "Insert Into AS9100-B Requirements(Section, Title, Applicability, Description) Values(" & Me!txtSection & ", " & Me!txtTitle & ", " & Me!txtApplicability & ", " & Me!txtDescription & ")"

I'm not overly familiar with VBA, so I very well may be doing something stupid.  But in some of the code you gave me you have # signs and single quotes.  Not sure if I should include those or not?
Also, do drop-down lists, or field type affect the entry into the table using this code?

Thanks for your help
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 21848790

private sub cmdCancel_click()

if me.dirty then me.undo

docmd.close acform, me.name

end sub
0
 

Author Closing Comment

by:Michael2008
ID: 31469844
Much easier, thanks for the help
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question