Prevent Subform from saving record or delete record when moving tomain form

R

RussCRM

I have a subform that allows me to enter records in table
"tblServices" that are linked to an individual "Guest Name". It is
embedded in a form linked to the table "tblGuest" for the "Guest Name"

When the user enters the Guest form, I have the subform automatically
set to go to a new record (otherwise it displays info from the guest's
last service record, which would end up getting edited and screwed up
because they wouldnt remember to click the Add Record button to go to
a new one.) I have that in the subform's OnCurrent code.

If the user starts adding a service record in the Services subform, I
only want to save the record if they click my cmdAddRecord button.
However, if they say, set the date on the subform and then get
distracted and click off the subform, it saves the record. I want to
prevent this because that seems to be happening. I'd like some way
to cancel or delete the record when they click off the subform to
prevent them from accidentally adding a record.

Ideas?
 
M

Marshall Barton

RussCRM said:
I have a subform that allows me to enter records in table
"tblServices" that are linked to an individual "Guest Name". It is
embedded in a form linked to the table "tblGuest" for the "Guest Name"

When the user enters the Guest form, I have the subform automatically
set to go to a new record (otherwise it displays info from the guest's
last service record, which would end up getting edited and screwed up
because they wouldnt remember to click the Add Record button to go to
a new one.) I have that in the subform's OnCurrent code.

If the user starts adding a service record in the Services subform, I
only want to save the record if they click my cmdAddRecord button.
However, if they say, set the date on the subform and then get
distracted and click off the subform, it saves the record. I want to
prevent this because that seems to be happening. I'd like some way
to cancel or delete the record when they click off the subform to
prevent them from accidentally adding a record.


You can force the use of your button by using a flag
variable that's set by the button and checked in the form's
BeforeUpdate event. The general idea of the code in the
subform's module would be along these lines:

Private bolSaveFlag As Boolean

Private Sub btnSave_Click()
bolSaveFlag = True
If Me.Dirty Then Me.Dirty = False 'save record
End Sub

Private Sub Form_Current()
bolSaveFlag = False
'Maybe you want to set AllowEdits to False
'to prevent changes to existing records??
End Sub

Private Sub Form_NeforeUpdate(Cancel ...)
If not bolSaveFlag Then
Cancel = True
Me.Undo
End If
End Sub
 

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