By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 820 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

Force user to save form data

P: n/a
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
Sep 3 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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:
>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

Sep 3 '08 #2

P: n/a
On Sep 3, 5:39*pm, "ErezM via AccessMonster.com" <u45095@uwewrote:
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:
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.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
Sep 3 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.