Is there a way to make the form not updatable unless the "Update"button is pressed?

R

Rhonda Floyd

I have a user that will start entering data on a form and press "Close" and the data that was entered updates the database.

I'm not exactly sure what I need to do to code this feature in. I only want the Table to be updated with new data or changed data when the "Update" command button is pressed.

Any help will be greatly appreciated.

Thanks.
 
H

HSalim

does your form have subforms? Do you have anything other than labels and
textboxes?
assuming no to both, follow these steps:

1. Add a module level OkToUpdate as Boolean

2. Attach the following code to the form's BeforeUpdate event
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
if Me.Dirty and Not OkToUpdate then
For Each ctl in Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Value = ctl.OldValue
End If
Next Ctl
End If
End Sub

3. attach the following to the update button

OKToUpdate = True
DoCmd.GoToRecord , , acNewRec ' or AcNext etc

if you have comboboxes etc, this gets a bit more complicated..




I have a user that will start entering data on a form and press "Close" and
the data that was entered updates the database.

I'm not exactly sure what I need to do to code this feature in. I only want
the Table to be updated with new data or changed data when the "Update"
command button is pressed.

Any help will be greatly appreciated.

Thanks.
 
R

Rhonda

Thanks, luckily my form isn't complicated.

Thanks again for your help.
Rhonda
does your form have subforms? Do you have anything other than labels and
textboxes?
assuming no to both, follow these steps:

1. Add a module level OkToUpdate as Boolean

2. Attach the following code to the form's BeforeUpdate event
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
if Me.Dirty and Not OkToUpdate then
For Each ctl in Me.Controls
If ctl.ControlType = acTextBox Then
ctl.Value = ctl.OldValue
End If
Next Ctl
End If
End Sub

3. attach the following to the update button

OKToUpdate = True
DoCmd.GoToRecord , , acNewRec ' or AcNext etc

if you have comboboxes etc, this gets a bit more complicated..




I have a user that will start entering data on a form and press "Close" and
the data that was entered updates the database.

I'm not exactly sure what I need to do to code this feature in. I only want
the Table to be updated with new data or changed data when the "Update"
command button is pressed.

Any help will be greatly appreciated.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top