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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When closing a form a record is saved.

Status
Not open for further replies.

Ascentient

IS-IT--Management
Nov 4, 2002
267
I have a previously existing program that I have been charge with "ID 10 T" proofing.

In this last week things that had originally worked seem to be not working.

Background:
A form is bound to a table. The txtBoxes are bound to the control source of the form.

Example:
When the Exit/Delete button is clicked it is suppose to close the form with out saving the record.
Well, it saves the record in the table.
Code:
DoCmd.Close acForm, "frmBmtic", acSaveNo

Am I missing something?

Ascent
 
From what I understand, the DoCmd.Close Save part is only asking if you want to save changes to the form itself not the record. If you wanted to save the record but without any of the changes taking effect then one way that I could think to do is to add Me.Undo above the DoCmd.Close

Me.Undo
DoCmd.Close acForm, "frmBmtic", acSaveNo

HTH,
Shane
 
Careful now - you haven't trapped all the ways a user can save a record now, have you?

What if the user hits the recordselector, hits Shift+Enter, moves to another record - how do you determine what is a success in this scenario - if the record is alredy saved, you should delete it?

Roy-Vidar
 
Hi Roy,
Thanks for the cross check.

The form contains all the fields of the record stored in the table. Another words the view type is Single Form.

As the user enters data into the fields it is automatically placing it into a new record in the table.

Well, if they hit the Exit/Delete Button I want that information to "go away".

The record selector or navigation buttons are not available to the user so they cannot move or a create a new record with out doing one of the following:

1.) Clicking on the Exit/Delete Button
2.) Clicking on the Print/Save Button and
3.) Clicking on the Print Quote Button.

I also have the form and programs 'x' close methods disabled too. (I know this also allowed the records to be saved.)

If you see or know of any other methods that will allow the record creation to succeed please advise.

Ascent

Side Note:
If my company would allow me to rewrite this application I would. It is a mess and has way to many holes in it for users to corrupt and input invalid data. I was lucky enough to get them to approve some "ID 10 T" error checking to resolve many of the current issues the end-users are currently experiencing.


 
So - if there is a record, and this button is hit, you want to remove it.

OK - check for me.newrecord - if true, you could just use me.undo, if false, then it's probably alredy saved. If you're using autonumbers, then the primary key is probably populated - you could just run a delete query where the field equals the contents of your control bound to the primary key field (and also test whether it is Null, in which case you're probably at an new record, without having anything entered).

Another couple of things to trap - what if the user hits ctrl+w or ctrl+F4 in the form ... ;-)

Roy-Vidar
 
Good call on the last two items, though it would be some fluke of nature if the users of this app were capabale of pressing those combinations.

I will work in your first options and trap the other two.

Thanks again.
Ascent
 
Roy,
I have placed the following code on my form. I have enabled KeyPreview on the form, but I still have problems with the form saving records when Ctrl+W, Ctrl+F4, and Ctrl+S is pressed. I thought I had it working, but for whatever reason, it is not.

Thoughts?

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   Dim l1 As Variant
   l1 = vbKeyControl
   Select Case KeyCode
      Case vbKeyControl
         KeyCode = 0
   End Select
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
   Dim l1 As Variant
   l1 = vbKeyControl
   Select Case KeyAscii
      Case vbKeyControl
         KeyAscii = 0
   End Select
End Sub
 
You wanted something like this ?
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If (Shift And acCtrlMask) > 0 Then
KeyCode = 0
End If
End Sub



Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I am sorry it has taken me so long to post a response back to this thread. (My family has all been sick.)

Thanks for the post PHV. That did the trick.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top