Solved

Closing Data Entry Form without saving

Posted on 2008-06-23
7
767 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

732 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