Solved

Closing Data Entry Form without saving

Posted on 2008-06-23
7
762 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 33

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 33

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 33

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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 33

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now