Connecting Tech Pros Worldwide Forums | Help | Site Map

Force user to save form data

Cron
Guest
 
Posts: n/a
#1: Sep 3 '08
Hi I'm trying to make a form that makes it optional for the user to
save the inputted data. If the user does not tap the save button
before leaving the form, the data is silently discarded.

This may seem like a strange request but it's a search form I'm
working on and I'd like the option to save common searches, so I've
set up a table to store saved searches.

Thanks for any help!
Ciarán

ErezM via AccessMonster.com
Guest
 
Posts: n/a
#2: Sep 3 '08

re: Force user to save form data


hi
you can tacle this from 2 different sides:
either have
1. the form's controls (and the form itself) be unbound to anything, then
only when the SAVE button is clicked use code to save the details to a table
Private Sub cmdSave_Click()
Dim rs As New ADODB.Recordset

rs.Open "SavedSearches", CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
rs!Field1 = TextBox1
rs!Field2 = ComboBox2
rs!Field3 = CheckBox3
rs!Field4 = SomethingElse
rs.Update
rs.Close
Set rs = Nothing
End Sub

2. have the form and all it's controls be bound to the SavedSearches table,
then add a variable in the form's code window
Private SaveClicked as Boolean

then use
Private Sub cmdSave_Click()
SaveClicked=True
End Sub

and then, use the Form_Unload event to check the condition of SaveClicked. if
it's true, just let access save the record automatically, otherwise, undo the
changes

Private Sub Form_Unload(Cancel As Integer)
If SaveClicked=False Then Me.Undo
End Sub

i prefer solution 1, it's cleaner and safer

good luck

Cron wrote:
Quote:
>Hi I'm trying to make a form that makes it optional for the user to
>save the inputted data. If the user does not tap the save button
>before leaving the form, the data is silently discarded.
>
>This may seem like a strange request but it's a search form I'm
>working on and I'd like the option to save common searches, so I've
>set up a table to store saved searches.
>
>Thanks for any help!
>Ciarán
--
May all beings be happy.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200809/1

Cron
Guest
 
Posts: n/a
#3: Sep 3 '08

re: Force user to save form data


On Sep 3, 5:39*pm, "ErezM via AccessMonster.com" <u45095@uwewrote:
Quote:
hi
you can tacle this from 2 different sides:
either have
1. the form's controls (and the form itself) be unbound to anything, then
only when the SAVE *button is clicked use code to save the details to atable
Private Sub cmdSave_Click()
Dim rs As New ADODB.Recordset
>
rs.Open "SavedSearches", CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
rs!Field1 = TextBox1
rs!Field2 = ComboBox2
rs!Field3 = CheckBox3
rs!Field4 = SomethingElse
rs.Update
rs.Close
Set rs = Nothing
End Sub
>
2. have the form and all it's controls be bound to the SavedSearches table,
then add a variable in the form's code window
Private SaveClicked as Boolean
>
then use
Private Sub cmdSave_Click()
SaveClicked=True
End Sub
>
and then, use the Form_Unload event to check the condition of SaveClicked.. if
it's true, just let access save the record automatically, otherwise, undothe
changes
>
Private Sub Form_Unload(Cancel As Integer)
If SaveClicked=False Then Me.Undo
End Sub
>
i prefer solution 1, it's cleaner and safer
>
good luck
>
Cron wrote:
Quote:
Hi I'm trying to make a form that makes it optional for the user to
save the inputted data. If the user does not tap the save button
before leaving the form, the data is silently discarded.
>
Quote:
This may seem like a strange request but it's a search form I'm
working on and I'd like the option to save common searches, so I've
set up a table to store saved searches.
>
Quote:
Thanks for any help!
Ciarán
>
--
May all beings be happy.
>
Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/databases-ms-access/2008...
Excellent, sounds doable - thanks a lot - I'll try it out tomorrow and
let you know how it goes!
Ciarán
Closed Thread