Tab problem

gguy

Registered User.
Local time
Today, 15:52
Joined
Jun 27, 2002
Messages
104
I have an entry form that has two command buttons. One is save and the other is close.
Both of these button work correctly, when I hit save and come back into the form it is ready for a new record, when I hit close and come back into the form it still shows the same record # as when I started the last record (and nothing is written to the table).
The problem is when I close the form using the X in the upper right and when I tab through the record without entering field information.
When I click the X in the upper right the record is accepted and when I tab through the record, the record is accepted and written to the table. I would like both of these situations to close without saving the record. Only the save button should save the record.
Thanks for any help, GGuy
 
The way I handled this is a little complex and needs some VBA code, but it is possible.

Step 1: In the general declaration of the form's Class Module, add a variable:

Dim boSaveButton as Boolean


Step 2: In the form's OnCurrent event routine, set boSaveButton to False

Step 3: In the Save buttons OnClick routine, set boSaveButton to True

Step 4: In the form's BeforeUpdate routine,

Cancel = CInt( Not boSaveButton )

What this does is it prevents the update unless you clicked your Save button.

OK, now, the problem this might create is that you can't leave using the Tab or X options you mentioned.

Well, for the form you could stop TAB from stepping to the next record (if that is what you wanted) by going into design mode for the form, open the form's properties, select the OTHER tab, and reset the Cycle property. This controls how the form reacts to a TAB character in the last field on the form. (I have mine set to Current Record as opposed to the other options.) So that takes care of the TAB-out problem.

In the Close button, you could do an UNDO first, THEN set the boSaveButton to True, then close the form. This allows you to leave via the close button without changing anything.
 
I am still looking at the VB code option that you suggested but I did modified the tab cycle. That modification does make the tab work as I wanted it to but it points out another problem.
When i click the save button, I want it to save the record, close the form and open another form. I have not been successful doing all three functions from the OnClick. So, I left the save and the close in the onclick and added the OpenForm function to OnExit.
Everything works correctly except when I tab over the save key it opens the new form.
Thanks again, GGuy
 

Users who are viewing this thread

Back
Top Bottom