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

Save Record

Status
Not open for further replies.

Bell1991

Programmer
Aug 20, 2003
386
US
Is it possible to have a form that does not save a record until the user clicks the button 'save record'.. My form currently will save the record even if the user closes the form..

Thanks,
-Bell
 
How are Bell1991 . . . . .

Yes! . . . use an [blue]unbound form[/blue] (all fields on the form are unbound). But you'll have to [blue]populate the actual fields[/blue] yourself before saving. Also if you want to parse thru records, you'll have to [blue]populate the controls[/blue] as well.

Calvin.gif
See Ya! . . . . . .
 
in from before update put this line
cancel= not me.activecontrol.name="btnSave"

 
Can i use a msgbox?

I am attempting it now, however, when i am not sure how to capture the user input:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim myVar
Code:
myVar = Msgbox("Do you wish to exit? You will lose any unsaved data.", 1, "Exit Test Scores?")

'Here is where i am doing something wrong

if myVar = 1 then  ' user selected yes
    'exit without saving
     DoCmd.Close
else 
    'go back to the form
     DoCmd.Restore
end if
End Sub

Will something like this work?



 
In the before update event of the form, you can do some of the following
- allow the save
- cancel the save (go back to the form as it was)
- undo

I don't think you can close the form there, but if the before update is triggered by trying to close the form, allowing the save or performing an undo, will probably allow the process (of closing the form) to proceed. A shortened version might perhaps look something like this.

[tt]retval = msgbox("Yes - save, No - undo, cancel - return to form", _
vbYesNoCancel,"???")
select case retval
case vbyes
' do nothing
case vbno
me.undo
case else
cancel = true
end select[/tt]

- typed, not tested.

You can off course also trigger this message only when the user attempts to close the form. This would probably mean to disallow the x button, and use a custom close button, setting a form public/private variable to test in the before update...

Roy-Vidar
 
When i use me.undo - the form still closes when i want it to remain open..

 
Have a look again at which alternative I stated would keep the form open.

Roy-Vidar
 
Also...
If you do not assign the primary key until the save button is clicked, the record can not be saved. This will not work for an AutoNumebr primary key but can be used for user entered primary keys or if you use code to generate a primary key.

For example, the user can enter the primary key into an unbound text box. When clicking the "Save" button, the value in the unbound text box is assigned to the primary key field (perhaps using a hidden text box that is bound to the primary key).

Using this approach, you can check for various conditions to ensure data integrity before allowing the "save".

Richard
 
On second thoughts, you probably need something more, including using your cusom close button, not the "x" in the corner. My second/third reply here thread702-866344, though "the other way around", could probably be tweaked to your purposes.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top