Solved

Closing Data Entry Form without saving

Posted on 2008-06-23
7
770 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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