Solved

Closing Data Entry Form without saving

Posted on 2008-06-23
7
757 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 119

Accepted Solution

by:
Rey Obrero 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

705 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

20 Experts available now in Live!

Get 1:1 Help Now