Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Newbie Question - canceling data entry

Status
Not open for further replies.

Milin

Technical User
Jan 5, 2000
33
US
Forgive me if this is a stupid question - I am new to foraying into the VB side of Access97<br>
<br>
I have created a small Rolodex database with one front end form that folks will use. I have set up three &quot;states&quot; of the form, View Only, Edit Mode, and Add a New Record Mode...all within one form. I have these differnt states activated by buttons, and have the fields lock or unlock with the &quot;enabled&quot; property on the buttons. The only part I can't get is that when the user goes into edit or new record mode, writes or deletes stuff, and then I give them a dialogue box that asks if they want to save or cancel, I don't understand how to do a true cancel and not have the new record added anyway, or the editing added anyway. I realize that as soon as someone types or deletes something, it's being instantly done in the source table, so is there some VBA way to undo that?? Like put the changes into some temporary la la land? As an example, here is the code I have for the save/cancel button in edit mode...<br>
<br>
Private Sub btnSaveEdit_Click()<br>
On Error GoTo Err_btnSaveEdit_Click<br>
Dim Savechoice<br>
<br>
Savechoice = MsgBox(&quot;Do you want to save your changes?&quot;, vbYesNo, &quot;Save&quot;)<br>
<br>
If Savechoice = vbYes Then<br>
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70<br>
<br>
Else<br>
DoCmd.CancelEvent<br>
<br>
End If<br>
Exit_btnSaveEdit_Click:<br>
Exit Sub<br>
<br>
Err_btnSaveEdit_Click:<br>
MsgBox Err.Description<br>
Resume Exit_btnSaveEdit_Click<br>
<br>
End Sub<br>
<br>
Please have mercy on my green-ness, o great ones! :)<br>
<br>

 
Try using Debug.print to see if infact the cancel button is giving the result you expect.<br>
Also put in Stops (Press F9) in the code window and use Ctrl-G to bring up the immediate window. <br>
type ?variablename and press the enter key<br>
you can see any value when tht program is in Halt mode.<br>
<br>
hope this helps
 
Try using the buttons to alter the &quot;Allow...&quot; properties instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top