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

Saving data only when button is pressed

Status
Not open for further replies.

sbeltyukov

Technical User
Jan 24, 2007
8
0
0
US
Hi,

I have a standard form that the user can fill out. When they start filling out the form and decide to go back (exit) without saving, it still saves the information into the table. Is it possible to save the information only after the save button has been pressed?

Thanks!
 
One way is to play with a public boolean variable.
In the Declarations section of the form's class module:
Dim bSavePressed As Boolean

In the Current event procedure of the form:
bSavePressed = False

In the Click event procedure of the save button:
bSavePressed = True
' your code saving the infos here

In the BeforeUpdate event procedure of the form:
If Not bSavePressed Then
MsgBox "save button not pressed !"
Cancel = True
Exit Sub
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That worked, but once I go back to actually add a record, the AutoNumber field is not 1 but 2. Is there any way to fix that?

Thanks for the help!
 
Any way to fix what ?
An AutoNumber should have no other meaning than to be unique !

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Oh, should I use a regular number field to create an item ID for each record?

Thanks!
 
You insist to have consecutive item IDs without gap ?
Have a look here: faq700-184

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I don't think I need that. The gaps should be fine. I have another question. I use two forms to add a single record so I put the code you provided into both forms. However, when I actually want to fill out the fields and save the record, when I click Continue on the first form to go to the second one, it doesn't let me because it executes the BeforeUpdate code. Is there any way to modify the code so that I could click Continue and go to the second form to continue entering the data?

Thanks!
 
Have you tried to set bSavePressed to true in the Click event procedure of the continue button ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top